|
| 1 | +import type { GuStackProps } from "@guardian/cdk/lib/constructs/core/stack.js"; |
| 2 | +import { GuStack } from "@guardian/cdk/lib/constructs/core/stack.js"; |
| 3 | +import { GuLambdaFunction } from "@guardian/cdk/lib/constructs/lambda/index.js"; |
| 4 | +import { GuS3Bucket } from "@guardian/cdk/lib/constructs/s3/index.js"; |
| 5 | +import type { App } from "aws-cdk-lib"; |
| 6 | +import { CustomResource } from "aws-cdk-lib"; |
| 7 | +import { Runtime } from "aws-cdk-lib/aws-lambda"; |
| 8 | +import { StringParameter } from "aws-cdk-lib/aws-ssm"; |
| 9 | + |
| 10 | +type Props = GuStackProps & { |
| 11 | + app: string; |
| 12 | +}; |
| 13 | + |
| 14 | +export class DictionaryDeployLambda extends GuStack { |
| 15 | + constructor(scope: App, id: string, props: Props) { |
| 16 | + super(scope, id, props); |
| 17 | + |
| 18 | + const { app } = props; |
| 19 | + |
| 20 | + const s3Bucket = GuS3Bucket.fromBucketName( |
| 21 | + this, |
| 22 | + "DictionaryDeployBucket", |
| 23 | + StringParameter.valueForStringParameter( |
| 24 | + this, |
| 25 | + `/account/services/dotcom-store.bucket`, |
| 26 | + ), |
| 27 | + ); |
| 28 | + |
| 29 | + const lambda = new GuLambdaFunction(this, "ID5BatonLambda", { |
| 30 | + functionName: `${app}-${this.stage}`, |
| 31 | + fileName: "lambda.zip", |
| 32 | + handler: "index.handler", |
| 33 | + app, |
| 34 | + runtime: Runtime.NODEJS_22_X, |
| 35 | + memorySize: 256, |
| 36 | + environment: { |
| 37 | + FASTLY_API_TOKEN: StringParameter.valueForStringParameter( |
| 38 | + this, |
| 39 | + `/${app}/${this.stage}/fastly-api-token`, |
| 40 | + ), |
| 41 | + FASTLY_AB_TESTING_CONFIG: |
| 42 | + StringParameter.valueForStringParameter( |
| 43 | + this, |
| 44 | + `/${app}/${this.stage}/fastly-ab-testing-config`, |
| 45 | + ), |
| 46 | + STAGE: this.stage, |
| 47 | + ARTIFACT_BUCKET_NAME: s3Bucket.bucketName, |
| 48 | + }, |
| 49 | + }); |
| 50 | + |
| 51 | + s3Bucket.grantRead(lambda); |
| 52 | + |
| 53 | + // Trigger the Lambda to run upon deployment |
| 54 | + new CustomResource(this, "InvokeDictionaryDeployLambda", { |
| 55 | + serviceToken: lambda.functionArn, |
| 56 | + }); |
| 57 | + } |
| 58 | +} |
0 commit comments