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

Passthrough metadata into SAM translator #3030

Merged
merged 2 commits into from Jan 22, 2024

Conversation

kddejong
Copy link
Contributor

@kddejong kddejong commented Jan 22, 2024

Issue #, if available:
fix #3028

Description of changes:

  • Add passthrough_metadata=True to SAM transform

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@kddejong
Copy link
Contributor Author

The following configuration is passed through and the error will be ignored

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS SAM template with a simple API definition
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      CacheClusterEnabled: true
      CacheClusterSize: '0.5'
      MethodSettings:
        - ResourcePath: /
          HttpMethod: GET
          CachingEnabled: true
          CacheTtlInSeconds: 300

  ApiFunction: # Adds a GET api endpoint at "/" to the ApiGatewayApi via an Api event
    Type: AWS::Serverless::Function
    Metadata:
      cfn-lint:
        config:
          ignore_checks:
            - E2531
    Properties:
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Path: /
            Method: get
            RestApiId:
              Ref: ApiGatewayApi
      Runtime: python2.7
      Handler: index.handler
      InlineCode: |
        def handler(event, context):
            return {'body': 'Hello World!', 'statusCode': 200}

@kddejong
Copy link
Contributor Author

Transforms into:

{
 "AWSTemplateFormatVersion": "2010-09-09",
 "Description": "AWS SAM template with a simple API definition",
 "Resources": {
  "ApiFunction": {
   "Metadata": {
    "cfn-lint": {
     "config": {
      "ignore_checks": [
       "E2531"
      ]
     }
    }
   },
   "Properties": {
    "Code": {
     "ZipFile": "def handler(event, context):\n    return {'body': 'Hello World!', 'statusCode': 200}\n"
    },
    "Handler": "index.handler",
    "Role": {
     "Fn::GetAtt": [
      "ApiFunctionRole",
      "Arn"
     ]
    },
    "Runtime": "python2.7",
    "Tags": [
     {
      "Key": "lambda:createdBy",
      "Value": "SAM"
     }
    ]
   },
   "Type": "AWS::Lambda::Function"
  },
  "ApiFunctionApiEventPermissionprod": {
   "Metadata": {
    "cfn-lint": {
     "config": {
      "ignore_checks": [
       "E2531"
      ]
     }
    }
   },
   "Properties": {
    "Action": "lambda:InvokeFunction",
    "FunctionName": {
     "Ref": "ApiFunction"
    },
    "Principal": "apigateway.amazonaws.com",
    "SourceArn": {
     "Fn::Sub": [
      "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/",
      {
       "__ApiId__": {
        "Ref": "ApiGatewayApi"
       },
       "__Stage__": "*"
      }
     ]
    }
   },
   "Type": "AWS::Lambda::Permission"
  },
  "ApiFunctionRole": {
   "Metadata": {
    "cfn-lint": {
     "config": {
      "ignore_checks": [
       "E2531"
      ]
     }
    }
   },
   "Properties": {
    "AssumeRolePolicyDocument": {
     "Statement": [
      {
       "Action": [
        "sts:AssumeRole"
       ],
       "Effect": "Allow",
       "Principal": {
        "Service": [
         "lambda.amazonaws.com"
        ]
       }
      }
     ],
     "Version": "2012-10-17"
    },
    "ManagedPolicyArns": [
     "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
    ],
    "Tags": [
     {
      "Key": "lambda:createdBy",
      "Value": "SAM"
     }
    ]
   },
   "Type": "AWS::IAM::Role"
  },
  "ApiGatewayApi": {
   "Properties": {
    "BodyS3Location": {
     "Bucket": "bucket",
     "Key": "value"
    }
   },
   "Type": "AWS::ApiGateway::RestApi"
  },
  "ApiGatewayApiDeployment6ab35d56ae": {
   "Properties": {
    "Description": "RestApi deployment id: 6ab35d56aec65900e2dcd7425c04f84894e835c5",
    "RestApiId": {
     "Ref": "ApiGatewayApi"
    },
    "StageName": "Stage"
   },
   "Type": "AWS::ApiGateway::Deployment"
  },
  "ApiGatewayApiprodStage": {
   "Properties": {
    "CacheClusterEnabled": true,
    "CacheClusterSize": "0.5",
    "DeploymentId": {
     "Ref": "ApiGatewayApiDeployment6ab35d56ae"
    },
    "MethodSettings": [
     {
      "CacheTtlInSeconds": 300,
      "CachingEnabled": true,
      "HttpMethod": "GET",
      "ResourcePath": "/"
     }
    ],
    "RestApiId": {
     "Ref": "ApiGatewayApi"
    },
    "StageName": "prod"
   },
   "Type": "AWS::ApiGateway::Stage"
  }
 }
}

@kddejong kddejong merged commit ff1d1d5 into aws-cloudformation:main Jan 22, 2024
21 checks passed
@kddejong kddejong deleted the fix/issue/3028 branch January 22, 2024 22:30
@mew1033
Copy link

mew1033 commented Jan 23, 2024

I'm still having issues with this: #3028 (comment)

@mew1033
Copy link

mew1033 commented Feb 5, 2024

It's working now. Sweet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use samtranslate passthrough_metadata to support ignoring checks on Serverless resources
2 participants