Skip to content

Commit 90d60ec

Browse files
committed
ensure error response gets sent
1 parent 092f3d8 commit 90d60ec

File tree

1 file changed

+27
-21
lines changed
  • ab-testing/dictionary-deploy-lambda/src

1 file changed

+27
-21
lines changed

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

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { configStruct } from "../../lib/config.ts";
77
import { FastlyClient } from "../../lib/fastly/client.ts";
88
import { fetchAndDeployArtifacts } from "./deploy.ts";
99

10-
const ssmClient = new SSMClient({ region: "eu-west-1" });
11-
1210
const getSecureString = async (name: string) => {
11+
const ssmClient = new SSMClient({ region: "eu-west-1" });
12+
1313
const response = await ssmClient.send(
1414
new GetParameterCommand({
1515
Name: name,
@@ -35,27 +35,33 @@ export const handler: Handler = async (
3535
event: CloudFormationCustomResourceEvent,
3636
context: Context,
3737
): Promise<void> => {
38-
const apiToken = await getSecureString(
39-
`/ab-testing-deploy/${process.env.STAGE}/fastly-api-token`,
40-
);
38+
try {
39+
const apiToken = await getSecureString(
40+
`/ab-testing-deploy/${process.env.STAGE}/fastly-api-token`,
41+
);
4142

42-
if (!apiToken) {
43-
throw new Error("Fastly API token not found in SSM Parameter Store");
44-
}
43+
if (!apiToken) {
44+
throw new Error(
45+
"Fastly API token not found in SSM Parameter Store",
46+
);
47+
}
4548

46-
const { serviceId, serviceName, abTestsDictionaryName, mvtDictionaryName } =
47-
await getFastlyConfig();
49+
const {
50+
serviceId,
51+
serviceName,
52+
abTestsDictionaryName,
53+
mvtDictionaryName,
54+
} = await getFastlyConfig();
4855

49-
const fastly = new FastlyClient(apiToken);
50-
const service = await fastly.getService(serviceId, serviceName);
56+
const fastly = new FastlyClient(apiToken);
57+
const service = await fastly.getService(serviceId, serviceName);
5158

52-
const abTestsDictionary = await service.getDictionary(
53-
abTestsDictionaryName,
54-
);
55-
const mvtDictionary = await service.getDictionary(mvtDictionaryName);
59+
const abTestsDictionary = await service.getDictionary(
60+
abTestsDictionaryName,
61+
);
62+
const mvtDictionary = await service.getDictionary(mvtDictionaryName);
5663

57-
if (event.RequestType === "Create" || event.RequestType === "Update") {
58-
try {
64+
if (event.RequestType === "Create" || event.RequestType === "Update") {
5965
await fetchAndDeployArtifacts([
6066
{
6167
artifact: "ab-test-groups.json",
@@ -68,9 +74,9 @@ export const handler: Handler = async (
6874
]);
6975

7076
send(event, context, "SUCCESS");
71-
} catch (error) {
72-
console.error("Error deploying dictionaries:", error);
73-
send(event, context, "FAILED");
7477
}
78+
} catch (error) {
79+
console.error("Error deploying dictionaries:", error);
80+
send(event, context, "FAILED", { error: (error as Error).message });
7581
}
7682
};

0 commit comments

Comments
 (0)