Skip to content

Commit

Permalink
Split edge stack
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptSmith committed Sep 8, 2023
1 parent d4c3b12 commit 5fb3070
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions edge.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 5 additions & 1 deletion template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Parameters:
SubnetIds:
Type: List<AWS::EC2::Subnet::Id>
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" ]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5fb3070

Please sign in to comment.