chalice icon indicating copy to clipboard operation
chalice copied to clipboard

Chalice generate-pipeline can create yaml incompatible with Cloudformation

Open corespace opened this issue 9 years ago • 7 comments

Hi folks,

I was working on a chalice app recently and decided to try out the chalice generate-pipeline feature. My app looked something like this:

from chalice import Chalice

app = Chalice(app_name='docGen')

@app.route('/some-path', methods=['POST'])
def generate_stuff():
    json_body = app.current_request.json_body
    return do_the_thing(json_body)

I've left out some details, obviously, but this is enough to see the problem. When I ran generate pipeline and deployed that pipeline, it built out a CloudFormation yaml that included this:

Resources:
  APIHandler:
    Properties:
      CodeUri: s3://some-s3-bucket
      Events:
        generate_stuffpostc666:
          Properties:
            Method: post
            Path: /some-path
            RestApiId:
              Ref: RestAPI
          Type: Api
      Handler: app.app
      MemorySize: 128
      Role: some-arn
      Runtime: python2.7
      Tags:
        aws-chalice: version=0.10.1:stage=dev:app=docGen
      Timeout: 60
    Type: AWS::Serverless::Function

Cool, right? Nope. Cloudformation barfed on this saying something to the effect "Event names must be alphanumeric" I don't have the exact error message anymore cause I went to retrieve it today and the ChangeSet is gone. Anyway, I created a test to reproduce the problem, but I'm not sure how you folks would want to rectify the problem. You can see it here: https://github.com/aws/chalice/compare/master...corespace:view_name?expand=1

corespace avatar Jul 31 '17 22:07 corespace

I guess event name is generated from the view.view_name + HTTPMethod + digest. In this case generated one is generate_stuffpostc666 which is not acceptable as cloudformation accepts only alphnumeric. Possible fix is to remove non alphnumeric characters from view.view_name and then generated the event name. I have a fix in mind . Can I raise a pull request ?

achautha avatar Aug 01 '17 10:08 achautha

@corespace, In your test case, you may want to check for other non alphanumeric characters too.

achautha avatar Aug 01 '17 15:08 achautha

Yeah I wanted a better test, but it's not clear to me which characters are allowed and which are not. I assume alphanumeric means letters and number but I couldn't find any documentation confirming that. Hence why I haven't offered a fix either.

corespace avatar Aug 01 '17 16:08 corespace

Thanks for reporting this one. Marking it as a bug.

stealthycoin avatar Aug 01 '17 16:08 stealthycoin

@stealthycoin, Can I take this up ? I have found the fix.

achautha avatar Aug 01 '17 17:08 achautha

@achautha Sure feel free to open a pull request.

stealthycoin avatar Aug 01 '17 17:08 stealthycoin

Fixed in https://github.com/aws/chalice/pull/453

jamesls avatar Aug 04 '17 20:08 jamesls