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

fix: prevent redundant tags being added to AWS::ApiGatewayV2::Api #3615

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions samtranslator/model/apigatewayv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ApiGatewayV2HttpApi(Resource):
}

runtime_attrs = {"http_api_id": lambda self: ref(self.logical_id)}
Tags: Optional[PassThrough]

def assign_tags(self, tags: Dict[str, Any]) -> None:
"""Overriding default 'assign_tags' function in Resource class
Expand All @@ -34,8 +33,8 @@ def assign_tags(self, tags: Dict[str, Any]) -> None:
:param tags: Tags to be assigned to the resource

"""
if tags is not None and "Tags" in self.property_types:
self.Tags = tags
# Tags are already defined in Body so they do not need to be assigned here
return


class ApiGatewayV2Stage(Resource):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyHttpApi:
Type: AWS::Serverless::HttpApi
Properties:
DefinitionBody:
openapi: 3.0.1
info:
title: My API
version: 1.0.0
paths:
/:
get:
x-amazon-apigateway-integration:
type: aws_proxy
httpMethod: POST
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambdaFunction.Arn}/invocations
responses:
'200':
description: OK
PropagateTags: true
Tags:
Project: MyProject


MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: hello.handler
Runtime: python3.10
CodeUri: s3://my-bucket/my-code.zip
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,6 @@
"x-amazon-apigateway-tag-value": "SAM"
}
]
},
"Tags": {
"Key1": "Value1",
"Key2": "Value2",
"httpapi:createdBy": "SAM"
}
},
"Type": "AWS::ApiGatewayV2::Api"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"MyHttpApi": {
aaythapa marked this conversation as resolved.
Show resolved Hide resolved
"Properties": {
"Body": {
"info": {
"title": "My API",
"version": "1.0.0"
},
"openapi": "3.0.1",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "OK"
}
},
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambdaFunction.Arn}/invocations"
}
}
}
}
},
"tags": [
{
"name": "Project",
"x-amazon-apigateway-tag-value": "MyProject"
},
{
"name": "httpapi:createdBy",
"x-amazon-apigateway-tag-value": "SAM"
}
]
}
},
"Type": "AWS::ApiGatewayV2::Api"
},
"MyHttpApiApiGatewayDefaultStage": {
"Properties": {
"ApiId": {
"Ref": "MyHttpApi"
},
"AutoDeploy": true,
"StageName": "$default",
"Tags": {
"Project": "MyProject",
"httpapi:createdBy": "SAM"
}
},
"Type": "AWS::ApiGatewayV2::Stage"
},
"MyLambdaFunction": {
"Properties": {
"Code": {
"S3Bucket": "my-bucket",
"S3Key": "my-code.zip"
},
"Handler": "hello.handler",
"Role": {
"Fn::GetAtt": [
"MyLambdaFunctionRole",
"Arn"
]
},
"Runtime": "python3.10",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"MyLambdaFunctionRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@
]
}
},
"FailOnWarnings": true,
"Tags": {
"TagKey1": "Value1",
"TagKey2": "Value2",
"httpapi:createdBy": "SAM"
}
"FailOnWarnings": true
},
"Type": "AWS::ApiGatewayV2::Api"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,6 @@
"x-amazon-apigateway-tag-value": "SAM"
}
]
},
"Tags": {
"Key1": "Value1",
"Key2": "Value2",
"httpapi:createdBy": "SAM"
}
},
"Type": "AWS::ApiGatewayV2::Api"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"MyHttpApi": {
"Properties": {
"Body": {
"info": {
"title": "My API",
"version": "1.0.0"
},
"openapi": "3.0.1",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "OK"
}
},
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambdaFunction.Arn}/invocations"
}
}
}
}
},
"tags": [
{
"name": "Project",
"x-amazon-apigateway-tag-value": "MyProject"
},
{
"name": "httpapi:createdBy",
"x-amazon-apigateway-tag-value": "SAM"
}
]
}
},
"Type": "AWS::ApiGatewayV2::Api"
},
"MyHttpApiApiGatewayDefaultStage": {
"Properties": {
"ApiId": {
"Ref": "MyHttpApi"
},
"AutoDeploy": true,
"StageName": "$default",
"Tags": {
"Project": "MyProject",
"httpapi:createdBy": "SAM"
}
},
"Type": "AWS::ApiGatewayV2::Stage"
},
"MyLambdaFunction": {
"Properties": {
"Code": {
"S3Bucket": "my-bucket",
"S3Key": "my-code.zip"
},
"Handler": "hello.handler",
"Role": {
"Fn::GetAtt": [
"MyLambdaFunctionRole",
"Arn"
]
},
"Runtime": "python3.10",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"MyLambdaFunctionRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@
]
}
},
"FailOnWarnings": true,
"Tags": {
"TagKey1": "Value1",
"TagKey2": "Value2",
"httpapi:createdBy": "SAM"
}
"FailOnWarnings": true
},
"Type": "AWS::ApiGatewayV2::Api"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,6 @@
"x-amazon-apigateway-tag-value": "SAM"
}
]
},
"Tags": {
"Key1": "Value1",
"Key2": "Value2",
"httpapi:createdBy": "SAM"
}
},
"Type": "AWS::ApiGatewayV2::Api"
Expand Down
Loading