Skip to content

Commit f8eee8b

Browse files
committed
read config from ssm
1 parent 1b3e319 commit f8eee8b

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

ab-testing/dictionary-deploy-lambda/src/index.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ import { GetParameterCommand, SSMClient } from "@aws-sdk/client-ssm";
22
import type { Handler } from "aws-cdk-lib/aws-lambda";
33
import type { CloudFormationCustomResourceEvent, Context } from "aws-lambda";
44
import { send } from "cfn-response";
5-
import {
6-
abTestsDictionaryId,
7-
abTestsDictionaryName,
8-
mvtDictionaryId,
9-
mvtDictionaryName,
10-
serviceId,
11-
serviceName,
12-
} from "../../lib/config.ts";
5+
import { assert } from "superstruct";
6+
import { configStruct } from "../../lib/config.ts";
137
import { FastlyClient } from "../../lib/fastly/client.ts";
148
import { fetchAndDeployArtifacts } from "./deploy.ts";
159

@@ -25,6 +19,18 @@ const getSecureString = async (name: string) => {
2519
return response.Parameter?.Value;
2620
};
2721

22+
const getFastlyConfig = async () => {
23+
const stringParam = await getSecureString(
24+
`/ab-testing-deploy/${process.env.STAGE}/fastly-ab-testing-config`,
25+
);
26+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- empty string is invalid JSON too
27+
const json = JSON.parse(stringParam || "{}") as unknown;
28+
29+
assert(json, configStruct);
30+
31+
return json;
32+
};
33+
2834
export const handler: Handler = async (
2935
event: CloudFormationCustomResourceEvent,
3036
context: Context,
@@ -37,6 +43,15 @@ export const handler: Handler = async (
3743
throw new Error("Fastly API token not found in SSM Parameter Store");
3844
}
3945

46+
const {
47+
serviceId,
48+
serviceName,
49+
abTestsDictionaryId,
50+
abTestsDictionaryName,
51+
mvtDictionaryId,
52+
mvtDictionaryName,
53+
} = await getFastlyConfig();
54+
4055
const fastly = new FastlyClient(apiToken);
4156
const service = await fastly.getService(serviceId, serviceName);
4257

ab-testing/lib/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ export {
4040
mvtDictionaryName,
4141
abTestsDictionaryId,
4242
abTestsDictionaryName,
43+
configStruct,
4344
};

0 commit comments

Comments
 (0)