Skip to content

HttpAPI properties are ignored when CorsConfiguration is not specified #2152

@kwojcik-blockether

Description

@kwojcik-blockether

Description:

Let's take as an example the following template.yml:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameters:
  Timeout:
    Type: Number
    Default: 40
  MemorySize:
    Type: Number
    Default: 2048
  Environment:
    Type: String
    Default: staging

Globals:
  Function:
    Timeout: !Ref Timeout
    MemorySize: !Ref MemorySize

Resources:
  ExampleOfHttpApi:
    Type: AWS::Serverless::HttpApi
    Properties:
      StageName: prod
      Description: "Some description"
      DisableExecuteApiEndpoint: True

  LambdaFunctionExample:
    Type: AWS::Serverless::Function
    Properties:
      Policies:
        - Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action:
              - "ec2:CreateNetworkInterface"
              - "ec2:DeleteNetworkInterface"
              - "ec2:DescribeNetworkInterfaces"
              - "ec2:DetachNetworkInterface"
            Resource: "*"
      VpcConfig:
        SecurityGroupIds:
          - "sg-0022f72578ac5b373"
        SubnetIds:
          - "subnet-09e403ca9d13578df"
          - "subnet-00eb630443da8fc42"
          - "subnet-0833fa017fa879075"
      FunctionName: !Sub "LambdaFunctionExample-${Environment}"
      PackageType: Image
      Events:
        HttpProxyEvent:
          Type: HttpApi
          Properties:
            ApiId: !Ref ExampleOfHttpApi
            Path: /{proxy+}
            Method: ANY
    Metadata:
      DockerTag: v1
      DockerContext: .
      Dockerfile: Dockerfile

This is perfectly valid template. What I found surprising is that the following properties are ignored:

  • HttpApi::Description
  • HttpApi::StageName
  • HttpApi::DisableExecuteApiEndpoint

Hovewer after adding CorsConfiguration the above specified properties works.

Steps to reproduce:

  1. Modify the template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameters:
  Timeout:
    Type: Number
    Default: 40
  MemorySize:
    Type: Number
    Default: 2048
  Environment:
    Type: String
    Default: staging

Globals:
  Function:
    Timeout: !Ref Timeout
    MemorySize: !Ref MemorySize

Resources:
  ExampleOfHttpApi:
    Type: AWS::Serverless::HttpApi
    Properties:
      StageName: prod
      Description: "Some description"
      DisableExecuteApiEndpoint: True

  LambdaFunctionExample:
    Type: AWS::Serverless::Function
    Properties:
      Policies:
        - Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action:
              - "ec2:CreateNetworkInterface"
              - "ec2:DeleteNetworkInterface"
              - "ec2:DescribeNetworkInterfaces"
              - "ec2:DetachNetworkInterface"
            Resource: "*"
      VpcConfig:
        SecurityGroupIds:
          - "sg-0022f72578ac5b373"
        SubnetIds:
          - "subnet-09e403ca9d13578df"
          - "subnet-00eb630443da8fc42"
          - "subnet-0833fa017fa879075"
      FunctionName: !Sub "LambdaFunctionExample-${Environment}"
      PackageType: Image
      Events:
        HttpProxyEvent:
          Type: HttpApi
          Properties:
            ApiId: !Ref ExampleOfHttpApi
            Path: /{proxy+}
            Method: ANY
    Metadata:
      DockerTag: v1
      DockerContext: .
      Dockerfile: Dockerfile
  1. Run sam build
  2. Run sam deploy --guided

Expected result:

I would expect that CorsConfiguration would not be required as it's specified in the documentation.
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-httpapi.html#sam-httpapi-corsconfiguration

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

  1. OS: Linux
  2. sam --version: 1.31.0
  3. AWS region: eu-central-1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions