I’m trying to deploy a custom resource using the CDK.
The following is the lambda code that is triggered by CloudFormation
export const handler = async (
event: Partial<CdkCustomResourceEvent> | undefined,
): Promise<CdkCustomResourceResponse> => {
const logger = pino();
logger.info({ event }, "event2");
const baseResponse: CdkCustomResourceResponse = {
StackId: event?.StackId,
RequestId: event?.RequestId,
LogicalResourceId: event?.LogicalResourceId,
PhysicalResourceId: "editor-db-schema-migrator",
};
return {
...baseResponse,
Status: "FAILED",
Reason: "terrible error",
Data: {
Result: new Error("TROLOLOLO"),
},
};
};
And the following is the CDK code that actually deploys the lambda:
const functionName = "editor-db-schema-migrator";
const onEventHandler = new Function(this, "MigratorFunction", {
functionName,
description:
"Lambda function running the Editor Database schema migrations during the deployment process.",
runtime: LAMBDA_RUNTIME,
code: Code.fromAsset(join(LAMBDA_DIR, functionName)),
handler: `${functionName}.handler`,
logRetention: getConfig().logs.logsGroupRetentionDays,
role: getDefaultLambdaRole(this, "MigrationFunctionRole", { functionName }),
vpc: props.vpc,
securityGroups: props.securityGroups,
});
const provider = new Provider(this, "CustomResourceProvider", {
onEventHandler,
logRetention: RetentionDays.ONE_DAY,
providerFunctionName: "EditorDbSchemaMigratorProvider",
});
new CustomResource(this, "EditorDbSchemaMigratorCustomResource", {
resourceType: "Custom::EditorDbSchemaMigrator",
serviceToken: provider.serviceToken,
properties: {
test: "10",
},
});
Now, I can see that the lambda is actually triggered during the deployment, however, even though I’m returning the “FAILED” status, CloudFormation continues with the deployment as if nothing happened. I need it to fail. What am I missing here?