Skip to content

Commit ff889d4

Browse files
trying to invoke getLetters
1 parent 577b851 commit ff889d4

14 files changed

Lines changed: 16724 additions & 15848 deletions

File tree

infrastructure/terraform/components/api/module_lambda_supplier_mock.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ module "supplier_mock" {
3434
log_destination_arn = local.destination_arn
3535
log_subscription_role_arn = local.acct.log_subscription_role_arn
3636

37-
lambda_env_vars = merge(local.common_lambda_env_vars, {})
37+
lambda_env_vars = merge(local.common_lambda_env_vars, {
38+
ENVIRONMENT = var.environment
39+
})
3840
}
3941

4042
data "aws_iam_policy_document" "supplier_mock_lambda" {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is auto generated by SAM CLI build command
2+
3+
[function_build_definitions.ab532b0c-d352-4f7f-8b49-59aa4765dd94]
4+
codeuri = "/workspaces/nhs-notify-supplier-api/lambdas/supplier-mock/dist"
5+
runtime = "nodejs22.x"
6+
architecture = "x86_64"
7+
handler = "index.handler"
8+
manifest_hash = ""
9+
packagetype = "Zip"
10+
functions = ["SupplierMockFunction"]
11+
12+
[layer_build_definitions]

lambdas/supplier-mock/.aws-sam/build/SupplierMockFunction/index.js

Lines changed: 138 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lambdas/supplier-mock/.aws-sam/build/SupplierMockFunction/index.js.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Resources:
4+
SupplierMockFunction:
5+
Type: AWS::Serverless::Function
6+
Properties:
7+
FunctionName: supplier_mock
8+
Runtime: nodejs22.x
9+
Handler: index.handler
10+
CodeUri: SupplierMockFunction
11+
MemorySize: 512
12+
Timeout: 29
13+
Metadata:
14+
SamResourceId: SupplierMockFunction
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
npm run lambda-build
4+
sam build
5+
sam local invoke SupplierMockFunction --event event.json

lambdas/supplier-mock/event.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "Vlasios"
3+
}

lambdas/supplier-mock/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"dependencies": {
3+
"@aws-sdk/client-api-gateway": "^3.1030.0",
4+
"@aws-sdk/client-lambda": "^3.1030.0",
35
"@internal/helpers": "^0.1.0",
46
"aws-embedded-metrics": "^4.2.1",
57
"aws-lambda": "^1.0.7",

lambdas/supplier-mock/src/deps.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,55 @@
11
import { Logger } from "pino";
22
import { createLogger } from "@internal/helpers/src";
3+
import { LambdaClient } from "@aws-sdk/client-lambda";
4+
import {
5+
APIGatewayClient,
6+
paginateGetRestApis,
7+
} from "@aws-sdk/client-api-gateway";
38
import { EnvVars, envVars } from "./env";
49

510
export type Deps = {
611
logger: Logger;
712
env: EnvVars;
13+
lambdaClient: LambdaClient;
14+
apiClient: APIGatewayClient;
15+
baseUrl: string;
816
};
917

10-
export function createDependenciesContainer(): Deps {
18+
export async function createDependenciesContainer(): Promise<Deps> {
1119
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
20+
const lambdaClient = new LambdaClient();
21+
const apiClient = new APIGatewayClient();
22+
const baseUrl = await getRestApiGatewayBaseUrl(envVars, apiClient);
1223

1324
return {
1425
logger: log,
1526
env: envVars,
27+
lambdaClient,
28+
apiClient,
29+
baseUrl,
1630
};
1731
}
32+
33+
async function getRestApiGatewayBaseUrl(
34+
environment: EnvVars,
35+
apiClient: APIGatewayClient,
36+
): Promise<string> {
37+
console.log(
38+
"VLASIS - about to retrieve API Gateway base URL using API client",
39+
);
40+
// const apiName = `nhs-${environment.ENVIRONMENT}-supapi`;
41+
const apiName = `nhs-pr535-supapi`;
42+
const api = await getApi(apiName, apiClient);
43+
// return `https://${api.id}.execute-api.${environment.AWS_REGION}.amazonaws.com/main`;
44+
return `https://${api.id}.execute-api.eu-west-2.amazonaws.com/main`;
45+
}
46+
47+
async function getApi(apiName: string, client: APIGatewayClient) {
48+
for await (const page of paginateGetRestApis({ client }, {})) {
49+
const filtered = page.items?.filter((api) => api.name === apiName);
50+
if (filtered?.length === 1) {
51+
return filtered[0];
52+
}
53+
}
54+
throw new Error(`API with name "${apiName}" not found.`);
55+
}

lambdas/supplier-mock/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { z } from "zod";
22

33
const EnvVarsSchema = z.object({
44
PINO_LOG_LEVEL: z.coerce.string().optional(),
5+
ENVIRONMENT: z.string().optional(),
6+
AWS_REGION: z.string().optional(),
57
});
68

79
export type EnvVars = z.infer<typeof EnvVarsSchema>;

0 commit comments

Comments
 (0)