aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.35k stars 3.77k forks source link

sam: cdk synth is missing prop for CfnFunction #29297

Open AmazingDreams opened 4 months ago

AmazingDreams commented 4 months ago

Description:

I am trying to setup an SQS event handler with ReportBatchItemFailures enabled. I am using CDK. However, the option will still be disabled.

Steps to reproduce:

I am using this in CDK template:

        new sam.CfnFunction(this, 'some-function', {
            events: {
                sqs: {
                    type: 'SQS',
                    properties: {
                        queue: this.queue.queueArn,
                        batchSize: 10,
                        functionResponseTypes: [ 'ReportBatchItemFailures' ],
                    }
                }
            }
        });

Observed result:

The function response types are not inserted into the generated template:

  somefunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: somefunction
      Events:
        sqs:
          Properties:
            BatchSize: 10
            Queue:
              Fn::GetAtt:
              - somequeue
              - Arn
          Type: SQS

Expected result:

I expect the ReportBatchItemFailures to be injected into the generated template:

          Properties:
            BatchSize: 10
            Queue:
              Fn::GetAtt:
              - somequeue
              - Arn
            FunctionResponseTypes:
              - ReportBatchItemFailures

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

  1. OS: Windows
  2. sam --version:
  3. AWS region: eu-west-1
{
  "version": "1.109.0",
  "system": {
    "python": "3.11.7",
    "os": "Windows-10-10.0.22631-SP0"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "Not available",
    "terraform": "1.7.3"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Add --debug flag to command you are running

jysheng123 commented 4 months ago

Hi, thanks for bringing up this issue, since you are creating the SAM template from CDK directly, this is not being used in SAM CLI, sending this over to the appropriate SAM repo.

AmazingDreams commented 4 months ago

Seems related to this issue https://github.com/aws/serverless-application-model/issues/3322

I guess CDK does not have the latest model setup?

GavinZZ commented 4 months ago

Hi there, thanks for reaching out. I tested with this template

Resources:
  somefunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs12.x
      CodeUri: s3://bucket/key
      Events:
        sqs:
          Properties:
            BatchSize: 10
            Queue:
              Fn::GetAtt:
              - somequeue
              - Arn
          Type: SQS

SAM is correctly transforming the template and the resulted event source mapping has batch size defined. This should be forwarded to AWS CDK repo.

pahud commented 3 months ago

Yes I can reproduce this issue

    new sam.CfnFunction(this, 'some-function', {
      events: {
          sqs: {
              type: 'SQS',
              properties: {
                  queue: 'dummyArn',
                  batchSize: 10,
                  functionResponseTypes: ['foo'],
              }
          }
      }
    });

would synthesize into

  somefunction:
    Type: AWS::Serverless::Function
    Properties:
      Events:
        sqs:
          Properties:
            BatchSize: 10
            Queue: dummyArn
          Type: SQS

And functionResponseTypes is missing in the template.

AmazingDreams commented 3 months ago

Actually I am encountering more and more things that seem to be not included in CDK. As if the definitions for SAM are out of date.