aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

cloudformation package generates S3BodyLocation by default

Open dtimberlake opened this issue 9 years ago • 8 comments

Introduction

aws cloudformation package currently creates S3BodyLocation for AWS::ApiGateway::RestApi even when no swagger file is specified in the S3BodyLocation property. The default action is to zip the entire working directory and upload it to S3.

Since this this parameter is not required (you can specify an inline Body or just use other resources to specify your api), I believe this should only run when you explicitly specify a swagger file.

Reproduce

1. Create initial template

# template.yml
AWSTemplateFormatVersion: '2010-09-09'
Resources:
  RestApi:
    Type: AWS::ApiGateway::RestApi
    Properties:
        Name: !Ref AWS::StackName

2. Package code (this will zip your entire current directory and upload)

aws cloudformation package \
  --template-file template.yml \
  --s3-bucket <bucket> \
  --output-template-file package-template.yml

This generate package-template.yml

Resources:
  RestApi:
    Properties:
      BodyS3Location:
        Bucket: <bucket>
        Key: <key>
      Name:
        Ref: AWS::StackName
    Type: AWS::ApiGateway::RestApi

Workaround

Remove BodyS3Location once the template has been created and remove the uploaded artifact from S3. Can't do anything about the cost associated with the initial upload.

dtimberlake avatar Dec 13 '16 20:12 dtimberlake

Seems reasonable to me. @sanathkr what are your thoughts?

kyleknap avatar Dec 16 '16 22:12 kyleknap

Yeah, this makes sense. Thanks for making this change.

sanathkr avatar Dec 22 '16 00:12 sanathkr

Fixed via https://github.com/aws/aws-cli/pull/2322. Thanks again for the pull request.

jamesls avatar Jan 07 '17 00:01 jamesls

So i see this issue as closed but it is still happening to me using cloudformation package. Am i missing something? Is the fix not rolled out yet?

dksheffield avatar Feb 28 '17 17:02 dksheffield

What version of the API are you using? Also, can you show me the AWS::ApiGateway::RestApi resource portion of your config?

I tried it with the example above and it worked fine for me (I know, not what you're looking to hear).

dtimberlake avatar Mar 05 '17 04:03 dtimberlake

API Version - aws-cli/1.11.44 Python/2.7.12 Linux/4.4.0-64-generic botocore/1.5.7

not sure how to embed yaml code so here is the gist - https://gist.github.com/dksheffield/8e4654a0143d386b68e7d8a991544cfc

dksheffield avatar Mar 06 '17 16:03 dksheffield

This issue was in reference to AWS::ApiGateway::RestApi not AWS::Serverless::Api. Can you share the template that is output when you package that file?

dtimberlake avatar Mar 06 '17 17:03 dtimberlake

Using standard cft - when I package this - https://gist.github.com/dksheffield/80f332d1151c2fcb59307c44b739e680

It outputs this - https://gist.github.com/dksheffield/6e08182f695d8276afdf9d8a57bd868e

Which appears to be correct. It's when I package the AWS::Serverless::Api that it adds the line DefinitionUri: s3://candhtrailers.com-builds/contact-us-ms-builds/00aa6ea076936e6213225a697d33dee1 and that line messes up my deploy command.

I'll post this over on the Serverless API repo and see what they say. Thanks!

dksheffield avatar Mar 06 '17 17:03 dksheffield