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.38k forks source link

Resource metadata is removed when converting 'AWS::Serverless::Function' to 'AWS::Lambda::Function' #264

Closed sunnyone closed 3 years ago

sunnyone commented 6 years ago

"Metadata" in AWS::Serverless::Function is removed when it's converted to AWS::Lambda::Function.

  MyFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: index.handler
      Runtime: nodejs6.10
      Policies:
        - Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Action:
                - cloudformation:DescribeStackResource
              Resource: (...ARN...)
    Metadata:  # <--- REMOVED!!!
      CustomData: ABC
      ImageConvertFunctionArn: !ImportValue OtherFunctionArn

Resource metadata is useful to customize behaviors in a function on Lambda@Edge since it does not support environmental variables of Lambda.

jamesjia94 commented 6 years ago

Also running into the same issue

Simon2228 commented 5 years ago

Unfortunately, resource metadata is currently not supported in SAM yet. You can submit a PR for this feature. Otherwise, we will prioritize this accordingly.

jlhood commented 4 years ago

This issue came up for cfn-lint since Metadata can be used to add inline cfn-lint configuration within a template. See https://github.com/aws-cloudformation/cfn-python-lint/issues/1294 for details.

One question I have is: should SAM (1) pass Metadata on AWS::Serverless::Function through to just the AWS::Lambda::Function resource or (2) pass Metadata through to all resources created as a result of that AWS::Serverless::Function? My intuition is we should go with (1), but just wondering if anyone has a use case for (2)?

PatMyron commented 4 years ago

One question I have is: should SAM (1) pass Metadata on AWS::Serverless::Function through to just the AWS::Lambda::Function resource or (2) pass Metadata through to all resources created as a result of that AWS::Serverless::Function?

Inclined towards 2. Easier to support going forward and makes more sense for every AWS::Serverless resource type to blindly pass metadata to every resource it creates because we can't understand all use-cases. If we pick and choose passing to only certain resources created by AWS::Serverless resources, we end up with the same problem where there are still certain resources where customers cannot set metadata

drAlberT commented 4 years ago

Metadata should be supported, and preserved, in Globals too .. to avoid C&P Metadata in multiple function

RonitRudra commented 3 years ago

Any updates on preserving metadata? We're trying to use the resource-level metadata in order to support configuration of custom macros.

c2tarun commented 3 years ago

Closing this ticket as the fix is merged.

c2tarun commented 3 years ago

This issue is still not resolved from SAM side.

mndeveci commented 3 years ago

Closing this issue since it is been released with SAM v1.36.0 and SAM CLI v1.24.0.

You can read more about how resource level attributes are handled in SAM via our updated documentation; https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-resource-attributes.html

Thanks!