-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow SAM Api and HttpApi to Propagate Tags to Generated Resources (#…
- Loading branch information
Showing
25 changed files
with
1,186 additions
and
6 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
integration/combination/test_api_and_http_api_with_propagate_tags.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from unittest.case import skipIf | ||
|
||
from integration.config.service_names import HTTP_API, REST_API | ||
from integration.helpers.base_test import BaseTest | ||
from integration.helpers.resource import current_region_does_not_support | ||
|
||
|
||
@skipIf( | ||
current_region_does_not_support([HTTP_API, REST_API]), | ||
"REST_API or HTTP_API is not supported in this testing region", | ||
) | ||
class TestApiAndHttpiWithPropagateTags(BaseTest): | ||
def test_api_and_httpapi_with_propagate_tags(self): | ||
self.create_and_verify_stack("combination/api_with_propagate_tags") | ||
|
||
outputs = self.get_stack_outputs() | ||
|
||
api_client = self.client_provider.api_client | ||
api_v2_client = self.client_provider.api_v2_client | ||
|
||
tags = api_client.get_tags(resourceArn=outputs["ApiArn"]) | ||
self.assertEqual(tags["tags"]["Key1"], "Value1") | ||
self.assertEqual(tags["tags"]["Key2"], "Value2") | ||
|
||
tags = api_v2_client.get_tags(ResourceArn=outputs["HttpApiArn"]) | ||
self.assertEqual(tags["Tags"]["Tag1"], "value1") | ||
self.assertEqual(tags["Tags"]["Tag2"], "value2") |
38 changes: 38 additions & 0 deletions
38
integration/resources/expected/combination/api_with_propagate_tags.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[ | ||
{ | ||
"LogicalResourceId": "MyApiDeployment", | ||
"ResourceType": "AWS::ApiGateway::Deployment" | ||
}, | ||
{ | ||
"LogicalResourceId": "MyApi", | ||
"ResourceType": "AWS::ApiGateway::RestApi" | ||
}, | ||
{ | ||
"LogicalResourceId": "MyApiProdStage", | ||
"ResourceType": "AWS::ApiGateway::Stage" | ||
}, | ||
{ | ||
"LogicalResourceId": "MyFunction", | ||
"ResourceType": "AWS::Lambda::Function" | ||
}, | ||
{ | ||
"LogicalResourceId": "MyFunctionPostApiPermission", | ||
"ResourceType": "AWS::Lambda::Permission" | ||
}, | ||
{ | ||
"LogicalResourceId": "MyFunctionRestApiPermissionProd", | ||
"ResourceType": "AWS::Lambda::Permission" | ||
}, | ||
{ | ||
"LogicalResourceId": "MyFunctionRole", | ||
"ResourceType": "AWS::IAM::Role" | ||
}, | ||
{ | ||
"LogicalResourceId": "MyHttpApi", | ||
"ResourceType": "AWS::ApiGatewayV2::Api" | ||
}, | ||
{ | ||
"LogicalResourceId": "MyHttpApiApiGatewayDefaultStage", | ||
"ResourceType": "AWS::ApiGatewayV2::Stage" | ||
} | ||
] |
69 changes: 69 additions & 0 deletions
69
integration/resources/templates/combination/api_with_propagate_tags.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Resources: | ||
MyApi: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
StageName: Prod | ||
Tags: | ||
Key1: Value1 | ||
Key2: Value2 | ||
PropagateTags: true | ||
GatewayResponses: | ||
DEFAULT_4XX: | ||
ResponseParameters: | ||
Headers: | ||
Access-Control-Allow-Origin: "'*'" | ||
|
||
MyFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Handler: index.handler | ||
Runtime: nodejs14.x | ||
InlineCode: | | ||
exports.handler = async (event, context, callback) => { | ||
return { | ||
statusCode: 200, | ||
body: 'Success' | ||
} | ||
} | ||
Events: | ||
RestApi: | ||
Type: Api | ||
Properties: | ||
RestApiId: | ||
Ref: MyApi | ||
Method: get | ||
Path: /iam | ||
Auth: | ||
Authorizer: AWS_IAM | ||
|
||
PostApi: | ||
Type: HttpApi | ||
Properties: | ||
ApiId: | ||
Ref: MyHttpApi | ||
Method: POST | ||
Path: /post | ||
|
||
MyHttpApi: | ||
Type: AWS::Serverless::HttpApi | ||
Properties: | ||
Tags: | ||
Tag1: value1 | ||
Tag2: value2 | ||
|
||
Outputs: | ||
ApiArn: | ||
Description: API endpoint URL for Prod environment | ||
Value: | ||
Fn::Sub: | ||
- arn:${AWS::Partition}:apigateway:${AWS::Region}::/restapis/${ApiId} | ||
- ApiId: !Ref MyApi | ||
|
||
HttpApiArn: | ||
Description: API endpoint URL for Prod environment | ||
Value: | ||
Fn::Sub: | ||
- arn:${AWS::Partition}:apigateway:${AWS::Region}::/apis/${ApiId} | ||
- ApiId: !Ref MyHttpApi | ||
Metadata: | ||
SamTransformTest: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.