From 5fb30706cf06efd84269c8fc46c7be0d89bf7a8d Mon Sep 17 00:00:00 2001 From: ScriptSmith Date: Fri, 8 Sep 2023 15:55:18 +1000 Subject: [PATCH] Split edge stack --- buildspec.yml | 3 +++ edge.yaml | 38 ++++++++++++++++++++++++++++++++++++++ template.yaml | 6 +++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 edge.yaml diff --git a/buildspec.yml b/buildspec.yml index cefbdc6..d6e7068 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -12,6 +12,9 @@ phases: - echo "[profile account-role]\nrole_arn = ${ACCOUNT_ROLE}\ncredential_source = EcsContainer" >> ~/.aws/config build: commands: + - sam build -t edge.yaml + - sam deploy --config-env $ENV --s3-bucket $LAMBDA_BUCKET_NAME --s3-prefix $ENV-$STACK_NAME --stack-name $STACK_NAME-edge --capabilities CAPABILITY_IAM --profile account-role --region us-east-1 -t edge.yaml + - (cd api; npm install) - (cd api; npm run build) - sam build diff --git a/edge.yaml b/edge.yaml new file mode 100644 index 0000000..59d19bd --- /dev/null +++ b/edge.yaml @@ -0,0 +1,38 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: Edge Lambda +Resources: + EdgeFunction: + Type: AWS::Serverless::Function + Properties: + Architectures: + - x86_64 + Timeout: 5 + CodeUri: serve/ + Runtime: nodejs18.x + Handler: index.handler + AutoPublishAlias: edge + AssumeRolePolicyDocument: + Version: 2012-10-17 + Statement: + - Effect: Allow + Principal: + Service: + - lambda.amazonaws.com + - edgelambda.amazonaws.com + Action: + - sts:AssumeRole + Metadata: + BuildMethod: esbuild + BuildProperties: + EntryPoints: + - index.ts + Minify: true + Sourcemap: true + Target: "es2020" +Outputs: + EdgeLambdaVersion: + Description: ARN Of the Lambda at the latest version + Value: !Ref EdgeFunction.Version + Export: + Name: !Sub "${AWS::StackName}-EdgeLambdaVersion" \ No newline at end of file diff --git a/template.yaml b/template.yaml index 06c1135..5d44dca 100644 --- a/template.yaml +++ b/template.yaml @@ -58,6 +58,9 @@ Parameters: SubnetIds: Type: List Description: VPC subnets + EdgeStackName: + Type: String + Description: Name of the edge stack containing the routing lambda in us-east-1 Conditions: CreateARecords: !Not [ !Equals [ !Ref HostedZoneName, "" ] ] IsDev: !Equals [ !Ref Environment, "dev" ] @@ -160,7 +163,8 @@ Resources: QueryString: True LambdaFunctionAssociations: - EventType: viewer-request - LambdaFunctionARN: !Ref ServeFunction.Version + LambdaFunctionARN: + Fn::ImportValue: !Sub "EdgeStackName-EdgeLambdaVersion" PriceClass: PriceClass_All Logging: IncludeCookies: false