Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sam:CfnFunction is not generating 'ApiId' for events #27760

Open
arshikam opened this issue Oct 30, 2023 · 1 comment
Open

sam:CfnFunction is not generating 'ApiId' for events #27760

arshikam opened this issue Oct 30, 2023 · 1 comment
Labels
@aws-cdk/aws-events Related to CloudWatch Events bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@arshikam
Copy link

Describe the bug

For sam.CfnFunction in the events section, 'api_id' is not getting recognised.

This is the below code:

from aws_cdk import (
    # Duration,
    Stack,
    # aws_sqs as sqs,
    aws_sam as sam
)
import aws_cdk as core
from constructs import Construct

class HttpapiStack(Stack):

    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        my_api_gateway = sam.CfnHttpApi(
            self,
            f"HttpApiGateway",
            description="test,
            stage_name="$default",
            cors_configuration=sam.CfnHttpApi.CorsConfigurationObjectProperty(
                allow_headers=["*"],
                allow_methods=["GET", "PUT", "POST", "OPTIONS"],
                allow_origins=["*"],
                max_age=864000,
            ),
        )
        s3_signer_lambda = sam.CfnFunction(
            self,
            f"S3SignerLambda",
            description="test",
            timeout=900,
            role="arn:aws:iam::1234567890:role/lambdaexecutionrole",
            inline_code="return",
            handler="index.handler",
            runtime="python3.9",
            events={
                "S3Sign": sam.CfnFunction.EventSourceProperty(
                    properties=sam.CfnFunction.HttpApiEventProperty(
                        path="/s3-sign",
                        method="POST",
                        api_id= my_api_gateway.ref
                    ),
                    type="HttpApi"
                )
            },
        )

As per the code, in the events section of the CfnFunction, the value for 'api_id' is referenced from the 'CfnHttpApi' defined above so this should resolve as per the cfn return value.

Expected Behavior

The event section should be resolving as below:

  S3SignerLambda:
    Type: AWS::Serverless::Function
    Properties:
      Description: test
      Events:
        S3Sign:
          Properties:
            Method: POST
            Path: /s3-sign
            ApiId:
              Ref: HttpApiGateway
          Type: HttpApi

Current Behavior

However, it is resolving as below where it is observed that it is completely omitting the 'ApiId' property.

  S3SignerLambda:
    Type: AWS::Serverless::Function
    Properties:
      Description: test
      Events:
        S3Sign:
          Properties:
            Method: POST
            Path: /s3-sign
          Type: HttpApi

Reproduction Steps

Added the code to replicate the same above.

Possible Solution

As a workaround, using raw overrides as below is resolving the concern but this should not be an ideal case.

s3_signer_lambda.add_property_override("Events.S3Sign.Properties.ApiId", my_api_gateway.ref);

Additional Information/Context

No response

CDK CLI Version

2.96.2 and 2.103.0

Framework Version

No response

Node.js Version

v18.17.1

OS

macOS Ventura 13.5.2

Language

Python

Language Version

No response

Other information

No response

@arshikam arshikam added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 30, 2023
@github-actions github-actions bot added the @aws-cdk/aws-events Related to CloudWatch Events label Oct 30, 2023
@pahud pahud self-assigned this Oct 30, 2023
@pahud
Copy link
Contributor

pahud commented Oct 30, 2023

Yes I can confirm only path and method are synthesized. This seems to be a bug.

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-httpapi.html

@pahud pahud added p2 effort/medium Medium work item – several days of effort labels Oct 30, 2023
@pahud pahud removed their assignment Oct 30, 2023
@pahud pahud removed the needs-triage This issue or PR still needs to be triaged. label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-events Related to CloudWatch Events bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants