I’d like to see the proper buildspec and template.yml for a Serverless based CodePipeline.
- I have a working Serverless function (API Gateway/Lambda/Aurora) using serverless-webpack that deploys fine
- I have a default CodeCommit repo created by CodeStar Node/Express template, the pipeline works fine
- Combining the two gives me CF errors
Default buildspec provided by CS template:
version: 0.1
phases:
build:
commands:
- aws s3 cp --recursive public/ s3://$WEBSITE_S3_BUCKET/public/ --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
- sed -i -e "s|assets/|$WEBSITE_S3_PREFIX/public/assets/|g" public/index.html
- aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template template-export.json
artifacts:
type: zip
files:
- template-export.json
My buildspec:
version: 0.1
phases:
build:
commands:
- serverless deploy
install:
commands:
- npm install
- npm install -g serverless
CS provided template.yml:
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
- AWS::CodeStar
Parameters:
ProjectId:
Type: String
Description: AWS CodeStar projectID used to associate new resources to team members
Resources:
GetHelloWorld:
Type: AWS::Serverless::Function
Properties:
Handler: index.get
Runtime: nodejs4.3
Role:
Fn::ImportValue:
!Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
Events:
GetEvent:
Type: Api
Properties:
Path: /
Method: get
My serverless.yml
service: xxx
provider:
name: aws
runtime: nodejs6.10
region: us-xxx-x
vpc:
securityGroupIds:
- sg-xxx
subnetIds:
- subnet-xxx
- subnet-xxx
- subnet-xxx
plugins:
- serverless-webpack
custom:
- webpackIncludeModules: true
functions:
read:
handler: handler.read
events:
- http:
path: /
method: get
My .babelrc
{
"plugins": ["transform-runtime"],
"presets": ["env"]
}
My .webpack.config.js
module.exports = {
entry: './handler.js',
target: 'node',
rules: [
{ test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" }
]
};
I get an S3 access denied error on the CF stack update. I’ve tried a few things but to no avail. Seems like someone should have a boilerplate for this type of setup?