aws / serverless-application-model

The AWS Serverless Application Model (AWS SAM) transform is a AWS CloudFormation macro that transforms SAM templates into CloudFormation templates.
https://aws.amazon.com/serverless/sam
Apache License 2.0
9.34k stars 2.38k forks source link

HTTP API duplicate integration #2720

Open mims92 opened 3 years ago

mims92 commented 3 years ago

Description:

I want to use the same Lambda for 2 routes:

I created 2 events in the same Serverless::Function definition. The result is that it created 2 separate integrations with the same Lambda function.

Steps to reproduce:

    ApiG:
        Type: AWS::Serverless::HttpApi
        Properties:
            CorsConfiguration:
                AllowHeaders: "*"
                AllowMethods:
                    - GET
                    - POST
                    - DELETE
                    - HEAD
                    - PUT
                    - PATCH
                AllowOrigins:
                    - '*'
                EndpointConfiguration: REGIONAL
                SecurityPolicy: TLS_1_2
            StageName: api

    ProxyServiceFunction:
        Type: AWS::Serverless::Function
        Properties:
            FunctionName: proxy
            CodeUri: proxy/src/
            Handler: index.handler
            Runtime: nodejs12.x
            Events:
                API1:
                    Type: HttpApi
                    Properties:
                        PayloadFormatVersion: "2.0"
                        Path: /api/{id}
                        Method: any
                        ApiId: !Ref ApiG
                API2:
                    Type: HttpApi
                    Properties:
                        PayloadFormatVersion: "2.0"
                        Path: /api/{id}/{proxy+}
                        Method: any
                        ApiId: !Ref ApiG

Observed result:

2 different integrations are created.

Expected result:

1 integration is created and attached to the two routes.

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

  1. OS: Debian 10
  2. If using SAM CLI, sam --version: 1.21.1
  3. AWS region: eu-central-1
aahung commented 3 years ago

Re-labeling it to a feature request. SAM creates one integration for each event even it is using the same HTTP API. We can de-duplicate such integration creations

jfuss commented 1 year ago

Looks like this was suppose to be on SAM Spec rather than the CLI. Moving to the correct repo.