Skip to content

Commit 6e34bbd

Browse files
authored
Merge pull request #3242 from aws/release-v1.71.0
Release 1.71.0 (to main)
2 parents 75b7858 + d1685e2 commit 6e34bbd

File tree

105 files changed

+23074
-3244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+23074
-3244
lines changed

.cfnlintrc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ ignore_templates:
129129
- tests/translator/output/**/managed_policies_minimal.json # Intentionally has non-existent managed policy name
130130
- tests/translator/output/**/function_with_mq.json # Property "EventSourceArn" can Fn::GetAtt to a resource of types [AWS::DynamoDB::GlobalTable, AWS::DynamoDB::Table, AWS::Kinesis::Stream, AWS::Kinesis::StreamConsumer, AWS::SQS::Queue]
131131
- tests/translator/output/**/function_with_mq_using_autogen_role.json # Property "EventSourceArn" can Fn::GetAtt to a resource of types [AWS::DynamoDB::GlobalTable, AWS::DynamoDB::Table, AWS::Kinesis::Stream, AWS::Kinesis::StreamConsumer, AWS::SQS::Queue]
132+
- tests/translator/output/**/function_with_tracing.json # Obsolete DependsOn on resource
133+
- tests/translator/output/**/api_with_propagate_tags.json # TODO: Intentional error transform tests. Will be updated.
132134
ignore_checks:
133135
- E2531 # Deprecated runtime; not relevant for transform tests
134136
- W2531 # EOL runtime; not relevant for transform tests

DEVELOPMENT_GUIDE.md

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,16 @@ one python version locally and then have our ci (appveyor) run all supported ver
134134

135135
Transform tests ensure a SAM template transforms into the expected CloudFormation template.
136136

137-
When adding new transform tests, we have provided a script to help generate the transform test input
138-
and output files in the correct directory given a `template.yaml` file.
139-
```bash
140-
python3 bin/add_transform_test.py --template-file template.yaml
141-
```
142-
143-
This script will automatically generate the input and output files. It will guarantee that the output
144-
files have the correct AWS partition (e.g. aws-cn, aws-us-gov).
137+
We provide a script to help generate the transform test input
138+
and output files in the correct directory given a SAM template. For example:
145139

146-
For `AWS::ApiGateway::RestApi`, the script will automatically append `REGIONAL` `EndpointConfiguration`.
147-
To disable this feature, run the following command instead.
148140
```bash
149-
python3 bin/add_transform_test.py --template-file template.yaml --disable-api-configuration
150-
```
151-
152-
The script automatically updates hardcoded ARN partitions to match the output partition. To disable this, use:
153-
```bash
154-
python3 bin/add_transform_test.py --template-file template.yaml --disable-update-partition
141+
python3 bin/add_transform_test.py --template-file template.yaml
155142
```
156143

157-
Please always check the generated output is as expected. This tool does not guarantee correct output.
144+
> **Warning**
145+
>
146+
> Always check the generated output is as expected. This tool does not guarantee correct output.
158147
159148
#### Transform failures
160149

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fetch-schema-data:
6666
mkdir -p .tmp
6767

6868
rm -rf .tmp/aws-sam-developer-guide
69-
git clone --depth 1 https://github.com/awsdocs/aws-sam-developer-guide.git .tmp/aws-sam-developer-guide
69+
git clone --branch main --depth 1 https://github.com/awsdocs/aws-sam-developer-guide.git .tmp/aws-sam-developer-guide
7070

7171
rm -rf .tmp/aws-cloudformation-user-guide
7272
git clone --depth 1 https://github.com/awsdocs/aws-cloudformation-user-guide.git .tmp/aws-cloudformation-user-guide

bin/add_transform_test.py

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from copy import deepcopy
99
from pathlib import Path
1010
from typing import Any, Dict
11+
from unittest.mock import patch
1112

1213
import boto3
1314

14-
from samtranslator.translator.arn_generator import ArnGenerator
1515
from samtranslator.translator.managed_policy_translator import ManagedPolicyLoader
1616
from samtranslator.translator.transform import transform
1717
from samtranslator.yaml_helper import yaml_parse
@@ -28,16 +28,6 @@
2828
type=Path,
2929
default=Path("template.yaml"),
3030
)
31-
parser.add_argument(
32-
"--disable-api-configuration",
33-
help="Disable adding REGIONAL configuration to AWS::ApiGateway::RestApi",
34-
action="store_true",
35-
)
36-
parser.add_argument(
37-
"--disable-update-partition",
38-
help="Disable updating the partition of arn to aws-cn/aws-us-gov",
39-
action="store_true",
40-
)
4131
CLI_OPTIONS = parser.parse_args()
4232

4333

@@ -51,25 +41,6 @@ def write_json_file(obj: Dict[str, Any], file_path: Path) -> None:
5141
json.dump(obj, f, indent=2, sort_keys=True)
5242

5343

54-
def add_regional_endpoint_configuration_if_needed(template: Dict[str, Any]) -> Dict[str, Any]:
55-
for _, resource in template["Resources"].items():
56-
if resource["Type"] == "AWS::ApiGateway::RestApi":
57-
properties = resource["Properties"]
58-
if "EndpointConfiguration" not in properties:
59-
properties["EndpointConfiguration"] = {"Types": ["REGIONAL"]}
60-
if "Parameters" not in properties:
61-
properties["Parameters"] = {"endpointConfigurationTypes": "REGIONAL"}
62-
63-
return template
64-
65-
66-
def replace_aws_partition(partition: str, file_path: Path) -> None:
67-
template = read_json_file(file_path)
68-
updated_template = json.loads(json.dumps(template).replace("arn:aws:", f"arn:{partition}:"))
69-
file_path.write_text(json.dumps(updated_template, indent=2), encoding="utf-8")
70-
print(f"Transform Test output files generated {file_path}")
71-
72-
7344
def generate_transform_test_output_files(input_file_path: Path, file_basename: str) -> None:
7445
output_file_option = file_basename + ".json"
7546

@@ -82,20 +53,13 @@ def generate_transform_test_output_files(input_file_path: Path, file_basename: s
8253
"aws-us-gov": ("us-gov-west-1", TRANSFORM_TEST_DIR / "output" / "aws-us-gov" / output_file_option),
8354
}
8455

85-
for partition, (region, output_path) in transform_test_output_paths.items():
86-
# Set Boto Session Region to guarantee the same hash input as transform tests for API deployment id
87-
ArnGenerator.BOTO_SESSION_REGION_NAME = region
88-
# Implicit API Plugin may alter input template file, thus passing a copy here.
89-
output_fragment = transform(deepcopy(manifest), {}, ManagedPolicyLoader(iam_client))
90-
91-
if not CLI_OPTIONS.disable_api_configuration and partition != "aws":
92-
output_fragment = add_regional_endpoint_configuration_if_needed(output_fragment)
93-
94-
write_json_file(output_fragment, output_path)
95-
96-
# Update arn partition if necessary
97-
if not CLI_OPTIONS.disable_update_partition:
98-
replace_aws_partition(partition, output_path)
56+
for _, (region, output_path) in transform_test_output_paths.items():
57+
with patch("samtranslator.translator.arn_generator._get_region_from_session", return_value=region), patch(
58+
"boto3.session.Session.region_name", region
59+
):
60+
# Implicit API Plugin may alter input template file, thus passing a copy here.
61+
output_fragment = transform(deepcopy(manifest), {}, ManagedPolicyLoader(iam_client))
62+
write_json_file(output_fragment, output_path)
9963

10064

10165
def get_input_file_path() -> Path:

bin/sam-translate.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
help="Enables verbose logging",
5959
action="store_true",
6060
)
61+
parser.add_argument(
62+
"--stdout",
63+
help="Write transformed template to stdout instead of a file",
64+
action="store_true",
65+
)
6166
cli_options = parser.parse_args()
6267

6368
if cli_options.verbose:
@@ -100,14 +105,18 @@ def package(input_file_path: Path) -> Path:
100105
return package_output_template_file
101106

102107

103-
def transform_template(input_file_path: Path, output_file_path: Path): # type: ignore[no-untyped-def]
108+
def transform_template(input_file_path: Path, output_file_path: Path, stdout: bool): # type: ignore[no-untyped-def]
104109
with input_file_path.open() as f:
105110
sam_template = yaml_parse(f) # type: ignore[no-untyped-call]
106111

107112
try:
108113
cloud_formation_template = transform(sam_template, {}, ManagedPolicyLoader(iam_client))
109114
cloud_formation_template_prettified = json.dumps(cloud_formation_template, indent=1)
110115

116+
if stdout:
117+
print(cloud_formation_template_prettified)
118+
return
119+
111120
output_file_path.write_text(cloud_formation_template_prettified, encoding="utf-8")
112121

113122
print("Wrote transformed CloudFormation template to: ", output_file_path)
@@ -132,10 +141,10 @@ def deploy(template_file: Path) -> None:
132141

133142
if cli_options.command == "package":
134143
package_output_template_file = package(input_file_path)
135-
transform_template(package_output_template_file, output_file_path)
144+
transform_template(package_output_template_file, output_file_path, cli_options.stdout)
136145
elif cli_options.command == "deploy":
137146
package_output_template_file = package(input_file_path)
138-
transform_template(package_output_template_file, output_file_path)
147+
transform_template(package_output_template_file, output_file_path, cli_options.stdout)
139148
deploy(output_file_path)
140149
else:
141-
transform_template(input_file_path, output_file_path)
150+
transform_template(input_file_path, output_file_path, cli_options.stdout)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import HTTP_API, REST_API
4+
from integration.helpers.base_test import BaseTest
5+
from integration.helpers.resource import current_region_does_not_support
6+
7+
8+
@skipIf(
9+
current_region_does_not_support([HTTP_API, REST_API]),
10+
"REST_API or HTTP_API is not supported in this testing region",
11+
)
12+
class TestApiAndHttpiWithPropagateTags(BaseTest):
13+
def test_api_and_httpapi_with_propagate_tags(self):
14+
self.create_and_verify_stack("combination/api_with_propagate_tags")
15+
16+
outputs = self.get_stack_outputs()
17+
18+
api_client = self.client_provider.api_client
19+
api_v2_client = self.client_provider.api_v2_client
20+
21+
tags = api_client.get_tags(resourceArn=outputs["ApiArn"])
22+
self.assertEqual(tags["tags"]["Key1"], "Value1")
23+
self.assertEqual(tags["tags"]["Key2"], "Value2")
24+
25+
tags = api_v2_client.get_tags(ResourceArn=outputs["HttpApiArn"])
26+
self.assertEqual(tags["Tags"]["Tag1"], "value1")
27+
self.assertEqual(tags["Tags"]["Tag2"], "value2")

integration/combination/test_state_machine_with_schedule.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from parameterized import parameterized
44

55
from integration.config.service_names import STATE_MACHINE_CWE_CWS
6-
from integration.helpers.base_test import BaseTest
6+
from integration.helpers.base_test import BaseTest, nonblocking
77
from integration.helpers.common_api import get_policy_statements
88
from integration.helpers.resource import current_region_does_not_support
99

@@ -12,6 +12,7 @@
1212
current_region_does_not_support([STATE_MACHINE_CWE_CWS]),
1313
"StateMachine CweCws is not supported in this testing region",
1414
)
15+
@nonblocking
1516
class TestStateMachineWithSchedule(BaseTest):
1617
@parameterized.expand(
1718
[

integration/config/service_names.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
LAMBDA_URL = "LambdaUrl"
3333
LAMBDA_ENV_VARS = "LambdaEnvVars"
3434
EVENT_INVOKE_CONFIG = "EventInvokeConfig"
35-
EPHEMERAL_STORAGE = "EphemeralStorage"
3635
API_KEY = "ApiKey"
3736
APP_SYNC = "AppSync"
3837
SNS_FILTER_POLICY_SCOPE = "SnsFilterPolicyScope"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"LogicalResourceId": "MyApiDeployment",
4+
"ResourceType": "AWS::ApiGateway::Deployment"
5+
},
6+
{
7+
"LogicalResourceId": "MyApi",
8+
"ResourceType": "AWS::ApiGateway::RestApi"
9+
},
10+
{
11+
"LogicalResourceId": "MyApiProdStage",
12+
"ResourceType": "AWS::ApiGateway::Stage"
13+
},
14+
{
15+
"LogicalResourceId": "MyFunction",
16+
"ResourceType": "AWS::Lambda::Function"
17+
},
18+
{
19+
"LogicalResourceId": "MyFunctionPostApiPermission",
20+
"ResourceType": "AWS::Lambda::Permission"
21+
},
22+
{
23+
"LogicalResourceId": "MyFunctionRestApiPermissionProd",
24+
"ResourceType": "AWS::Lambda::Permission"
25+
},
26+
{
27+
"LogicalResourceId": "MyFunctionRole",
28+
"ResourceType": "AWS::IAM::Role"
29+
},
30+
{
31+
"LogicalResourceId": "MyHttpApi",
32+
"ResourceType": "AWS::ApiGatewayV2::Api"
33+
},
34+
{
35+
"LogicalResourceId": "MyHttpApiApiGatewayDefaultStage",
36+
"ResourceType": "AWS::ApiGatewayV2::Stage"
37+
}
38+
]

integration/resources/expected/single/function_with_ephemeral_storage.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)