S3 size limit on ApiGateway created by CloudFormation

Keywords:amazon  web  services 


I have a cloud formation template that defines a new api gateway:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: API for getting planetary info
    Type: AWS::ApiGateway::RestApi
      Name: "Planets API"

I have CodePipeline set up to create this as a change set and then execute the change set.

When the change set executes, it fails with the following error:

13:55:28 UTC-0400   CREATE_FAILED   AWS::ApiGateway::RestApi PlanetsApi S3 object size exceeds limit of 2 MB

I don't know where this limit is coming from, or why anything is being uploaded to S3. Google searches are turning up no useful information. Curiously, if I create the change set and execute through the CloudFormation console, I don't get any errors.

What am I doing wrong?

1 Answer: 

Had the same problem. And wow, I realized when I use aws cloudformation package, it creates a BodyS3Location with its properties (Bucket and key) under where I define my Type: AWS::ApiGateway::RestApi. This happens, even though I had not defined such parameters earlier in my template, before being processed by cloudformation package. This, then causes the error.

What I did to tackle this issue:

  1. Let the CodePipeline to run, and fail (with the error)

  2. Go to the AWS Console, find the failed stack, and expand Template

  3. Find the lines in which BodyS3Location and its parameters are generated (for me they were in lines 22 to 24)

  4. Add a command in buildspec.yml to delete these lines, after the package command (example below)

    • aws cloudformation package --s3-bucket some-s3bucket --template-file ./template.yml --output-template-file ./packaged-template.yml

    • sed --in-place '22,24d' packaged-template.yml

  5. commit and push to repo again

  6. It must work now!

Note: This is not the best solution, this issue must be solved, from AWS end!


It is something to do with the AWS CLI version. Try installing this version before running the cloudformation package command (in your CodeBuild), and you should be good to go.

pip install awscli==1.11.37