Skip to content

SAM CORS does not create needed Method Responses #640

@ehorodyski

Description

@ehorodyski

Description:

Invalid Response status code specified when trying to apply CORS to SAM-created API gateway endpoints.

Steps to reproduce the issue:

  1. Create a SAM template w/ CORS enabled
  2. Deploy and have artifacts created
  3. Attempt to set CORS

Observed result:

Error listed above. I think the issue is that the Method Responses that API Gateway automatically creates through the GUI when applying CORS are not being added to the endpoints that SAM creates. Therefore, when moving artifacts to another environment in a manual process (such as I have to do for my organization, we cannot use SAM to deploy Production-level artifacts) I run into the issue showed above.

sam issue
screen shot 2018-10-25 at 8 07 44 am

Expected result:

Set endpoints correctly. Addt., why are endpoints created through SAM automatically set to use proxy-integration?

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

Output of sam --version:
0.6.0

Optional Debug logs:
Sample Template.YAML (Acct. Credentials/Role obscured for security):

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: ROLE
Globals:
    Function:
        Timeout: 300
Resources:
    MyAPI:
        Type: AWS::Serverless::Api
        Properties:
            Name: my-api
            StageName: v1
            EndpointConfiguration: EDGE
            Cors:
                AllowMethods: "'GET,POST,PUT,DELETE'"
                AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
                AllowOrigin: "'*'"
    MyAPIFunction:
        Type: AWS::Serverless::Function
        Properties:
            FunctionName: my-api
            CodeUri: my-api-lambda/
            Handler: index.handler
            Runtime: nodejs8.10
            Role: arn:aws:iam::XXXXXX:role/role
            Description: This lambda runs functionality.
            Environment:
                Variables:
                    HIDDEN: True
            Events:
                Get:
                    Type: Api
                    Properties:
                        Path: /my/{id}
                        Method: post
                        RestApiId:
                            Ref: MyAPI
                Test:
                    Type: Api
                    Properties:
                        Path: /my/test
                        Method: post
                        RestApiId:
                            Ref: MyAPI
                Update:
                    Type: Api
                    Properties:
                        Path: /my/{id}
                        Method: put
                        RestApiId:
                            Ref: MyAPI
                Sync:
                    Type: Api
                    Properties:
                        Path: /my/sync/{id}
                        Method: get
                        RestApiId:
                            Ref: MyAPI
              

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions