@@ -2,14 +2,8 @@ import { GetParameterCommand, SSMClient } from "@aws-sdk/client-ssm";
22import type { Handler } from "aws-cdk-lib/aws-lambda" ;
33import type { CloudFormationCustomResourceEvent , Context } from "aws-lambda" ;
44import { 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" ;
137import { FastlyClient } from "../../lib/fastly/client.ts" ;
148import { 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+
2834export 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
0 commit comments