This Gist is based on Building a continuous delivery pipeline for a Lambda application with AWS CodePipeline.
Needed to build a NodeJS project, upload the static assets to an S3 bucket and also deploy a small Lambda function that lived in a subfolder.
The AWS Guide above will get you familiarized with the setup, but there are a couple of changes required on both the buildspec.yml and template.yml files.
You start at the root of your repo…which is nice.
Pre-build and build commands a pretty much self-explanatory.
For whatever reason the index.js, template.yml and outputtemplate.yml needed to be by themselves in a folder.
I had initially configured an Action in the Deploy stage that published the static assets to a static website hosting S3 Bucket. I removed it and used the aws s3 sync command instead.
version: 0.2 phases: pre_build: commands: - cd lambda-function/ - npm install - cd .. build: commands: - npm install && npm run build - aws cloudformation package --template-file lambda-function/template.yml --s3-bucket codepipeline-S3_BUCKET --output-template-file lambda-function/outputtemplate.yml --kms-key-id ID post_build: commands: - cd build/ - aws s3 sync . s3://static-assets-bucket/ artifacts: type: zip files: - lambda-function/template.yml - lambda-function/outputtemplate.yml discard-paths: yes
Nothing out of the ordinary really.
AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: My Lambda Function Resources: MyLambdaFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: nodejs12.x CodeUri: ./ Environment: Variables: AUTH_TOKEN: VAR Events: AuthProxyApi: Type: HttpApi Properties: Path: / Method: POST