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.29k stars 2.37k forks source link

EventInvokeConfig does not appear in processed template when following the spec #3602

Closed Tristano8 closed 1 month ago

Tristano8 commented 1 month ago

Description

Using an EventInvokeConfig results in a processed template that ignores these fields completely

Steps to reproduce

Deploy something like the following template:

Resources:
  ErrorReporterFunction:
    Properties:
      AutoPublishAlias: 'Live'
      CodeUri: 'bootstrap-file'
      FunctionName:
        'Fn::Sub': "${AWS::StackName}-error-reporter-function"
      Handler: 'UNUSED'
      LoggingConfig:
        ApplicationLogLevel: 'DEBUG'
        LogFormat: 'JSON'
        SystemLogLevel:
          Fn::FindInMap:
            - LambdaLogLevel
            - Ref: 'LogSeverity'
            - System
      MemorySize: 512
      Policies:
        - 'AWSLambdaBasicExecutionRole'
      Runtime: 'provided.al2'
      Timeout: 300
    Type: 'AWS::Serverless::Function'
  MyFunction:
    EventInvokeConfig:
      DestinationConfig:
        OnFailure:
          Destination': !GetAtt ErrorReporterFunction.Arn
          Type: 'Lambda'
    Properties:
      AutoPublishAlias: 'Live'
      CodeUri: 'other-bootstrap-file'
      FunctionName:
        'Fn::Sub': "${AWS::StackName}-my-lambda"
      Handler: 'UNUSED'
      LoggingConfig:
        ApplicationLogLevel: 'DEBUG'
        LogFormat: 'JSON'
        SystemLogLevel:
          Fn::FindInMap:
            - LambdaLogLevel
            - Ref: 'LogSeverity'
            - System
      MemorySize: 512
      Policies:
        - 'AWSLambdaBasicExecutionRole'
      Runtime: 'provided.al2'
      Timeout: 300
    Type: 'AWS::Serverless::Function'

Observed result

The processed template after deployment looks something like the following for MyFunction:

"MyFunction": {
      "Type": "AWS::Lambda::Function",
      "DependsOn": [
        "ValidationProducerFunctionLogGroup"
      ],
      "Properties": {
        "Code": {
          "S3Bucket": "<bucket-name>",
          "S3Key": "<bootstrap-hash>"
        },
        "FunctionName": {
          "Fn::Sub": "${AWS::StackName}-my-lambda"
        },
        "Handler": "UNUSED",
        "MemorySize": 512
}

No reference to the EventInvokeConfig exist anywhere in the processed template.

Deploying the following as a top level resource seems to work:

EventInvokeConfig:
    Type: AWS::Lambda::EventInvokeConfig
    Properties:
      FunctionName: !Ref MyFunction
      Qualifier: "Live"
      DestinationConfig:
        OnFailure:
          Destination: !GetAtt ErrorReporterFunction.Arn

Expected result

The transform should include my declared EventInvokeConfig in the processed template

Additional environment details

  1. OS: MacOs 14.4.1
  2. If using the SAM CLI, sam --version:
  3. AWS region: us-east-1
GavinZZ commented 1 month ago

In your function definition

MyFunction:
    EventInvokeConfig:
      DestinationConfig:
        OnFailure:
          Destination': !GetAtt ErrorReporterFunction.Arn
          Type: 'Lambda'
    Properties:
      AutoPublishAlias: 'Live'
      CodeUri: 'other-bootstrap-file'
      FunctionName:
        'Fn::Sub': "${AWS::StackName}-my-lambda"
      Handler: 'UNUSED'
      LoggingConfig:
        ApplicationLogLevel: 'DEBUG'
        LogFormat: 'JSON'
        SystemLogLevel:
          Fn::FindInMap:
            - LambdaLogLevel
            - Ref: 'LogSeverity'
            - System
      MemorySize: 512
      Policies:
        - 'AWSLambdaBasicExecutionRole'
      Runtime: 'provided.al2'
      Timeout: 300
    Type: 'AWS::Serverless::Function'

I believe you accidentally defined EventInvokeConfig outside of the properties. According to documentation, it should be under Properties

GavinZZ commented 1 month ago

Going to mark this issue as resolved. Feel free to open a new issue if it doesn't fix it and we're happy to help.

github-actions[bot] commented 1 month ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one.