Reputation: 507
I'm having problems getting AWS CodeBuild to Build and Deploy a project created using Serverless Framework.
Here is the story so far.
I've followed the docs to create the beginnings of a Serverless project and left "as is" - basically, "Hello World".
I've then put the project in a git repo.
Then, from the CLI, I've called...
serverless deploy
...and as expected the lambda has been deployed. A good start.
Next on the agenda was to have a go at building and deploying using AWS CodeBuild.
I've added a buildspec.yml
file in the root of the project:
version: 0.1
phases:
install:
commands:
- npm install
- npm install -g serverless
- echo install done
build:
commands:
- serverless deploy
- echo build done
Then, using the AWS Console/Web Interface, I've defined a code build project which references the git repo.
When doing so AWS created an IAM Role with the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": [
"arn:aws:logs:eu-west-1:************:log-group:/aws/codebuild/my-api-build",
"arn:aws:logs:eu-west-1:************:log-group:/aws/codebuild/my-api-build:*"
],
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
},
{
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::codepipeline-eu-west-1-*"
],
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectVersion"
]
},
{
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::my-api-artifacts/*"
],
"Action": [
"s3:PutObject"
]
}
]
}
So I pressed "Start Build" on the CodeBuild project and got the following errors:
ServerlessError: User: arn:aws:sts::************:assumed-role/codebuild-my-api-build-service-role/AWSCodeBuild-********-****-****-****-************ is not authorized to perform: cloudformation:DescribeStackResources on resource: arn:aws:cloudformation:eu-west-1:************:stack/my-api-development/*
which I "fixed" by adding the following to the policy created by code build...
{
"Effect": "Allow",
"Resource": [
"arn:aws:cloudformation:eu-west-1:*"
],
"Action": [
"cloudformation:*"
]
}
Pressed Start Build again and got:
An error occurred while provisioning your stack: ServerlessDeploymentBucket - API: s3:CreateBucket Access Denied.
which I "fixed" by adding the following to the policy created by code build...
{
"Effect": "Allow",
"Resource": [
"arn:aws:cloudformation:eu-west-1:*"
],
"Action": [
"cloudformation:*"
]
}
Serverless Error ---------------------------------------
Missing required key 'Bucket' in params
Missing required key 'Bucket' in params
mean? Where should I be looking?Upvotes: 4
Views: 2089
Reputation: 1083
I solved this problem, by adding(editing) stage: prod
into serverless.yml.
finally, it looks like this.
provider:
name: aws
runtime: python3.6
stage: prod
credentials:
accessKeyId: <your-access-id>
secretAccessKey: <your-secret-access-key>
Upvotes: 2