L G
L G

Reputation: 507

Serveless Framework and CodeBuild : Missing required key 'Bucket' in params

I'm having problems getting AWS CodeBuild to Build and Deploy a project created using Serverless Framework.

Here is the story so far.

Initialise the project

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.

Test deploy from CLI

Then, from the CLI, I've called...

serverless deploy

...and as expected the lambda has been deployed. A good start.

CodeBuild

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"
            ]
        }
    ]
}

Let's do this...

So I pressed "Start Build" on the CodeBuild project and got the following errors:

Error 1:

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:*"
    ]
}

Error 2:

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:*"
    ]
}

Error 3:

Serverless Error ---------------------------------------

Missing required key 'Bucket' in params

Finally: My actual question(s)

  1. What does Missing required key 'Bucket' in params mean? Where should I be looking?
  2. Are my "fixes" to Error 1 and 2 OK? I'm Bit of an AWS and therefore IAM newbie so I'm not that confident when editing policies.

Upvotes: 4

Views: 2089

Answers (2)

Lasith Niroshan
Lasith Niroshan

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

L G
L G

Reputation: 507

@Unsigned - Thanks for the comment.

Although your recommendation to delete and redeploy didn't work the link you posted did mention having S3 privileges.

I added Full S3 Access to my code build role and k'boom, it worked.

Upvotes: 2

Related Questions