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

Release 1.71.0 (to main) #3242

Merged
merged 22 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b02c0a4
chore(schema): update (#3192)
github-actions[bot] Jun 1, 2023
1737834
chore: make statemachine cw events test nonblocking (#3196)
aaythapa Jun 1, 2023
fd19feb
feat: make `add_transform_test.py` always match expected output (#3195)
hoffa Jun 1, 2023
27dfa85
Allow SAM Api and HttpApi to Propagate Tags to Generated Resources (#…
GavinZZ Jun 1, 2023
6a58236
Allow SAM Function and SAM StateMachines to Propagate Tags to Generat…
GavinZZ Jun 2, 2023
6571ce8
chore(schema): update (#3199)
github-actions[bot] Jun 5, 2023
dd095dc
chore: add test with Function and CloudWatch event (#3204)
hoffa Jun 5, 2023
68101bf
chore(schema): update (#3202)
github-actions[bot] Jun 5, 2023
cf96ec0
chore(schema): update (#3205)
github-actions[bot] Jun 6, 2023
af97ddd
chore(schema): update (#3206)
github-actions[bot] Jun 9, 2023
23a882b
chore(schema): update (#3207)
github-actions[bot] Jun 12, 2023
a9fad5b
chore(schema): update (#3208)
github-actions[bot] Jun 14, 2023
b4412e6
Merge branch 'develop' into tmp/1686853246/main
xazhao Jun 15, 2023
1940e31
Merge pull request #3212 from aws/tmp/1686853246/main
xazhao Jun 15, 2023
934f2ef
chore: remove ephemeral storage integ test (#3213)
xazhao Jun 16, 2023
237c739
fix: Remove validation of SNS Event FilterPolicy (#3216)
xazhao Jun 19, 2023
b82c33b
chore: use explicit `main` branch for SAM docs (#3217)
hoffa Jun 20, 2023
3bd8a54
chore: Add transform tests with Tracing Properties (#3221)
GavinZZ Jun 20, 2023
53eddc7
feat: add `--stdout` to `sam-translate.py` (#3222)
hoffa Jun 21, 2023
100cb5f
feat: Support Disabled Tracing Configuration (#3223)
GavinZZ Jun 21, 2023
51f7bf6
chore: bump version to 1.71.0
aws-sam-cli-bot Jul 5, 2023
d1685e2
Merge branch 'main' into release-v1.71.0
hoffa Jul 5, 2023
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
2 changes: 2 additions & 0 deletions .cfnlintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ ignore_templates:
- tests/translator/output/**/managed_policies_minimal.json # Intentionally has non-existent managed policy name
- 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]
- 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]
- tests/translator/output/**/function_with_tracing.json # Obsolete DependsOn on resource
- tests/translator/output/**/api_with_propagate_tags.json # TODO: Intentional error transform tests. Will be updated.
ignore_checks:
- E2531 # Deprecated runtime; not relevant for transform tests
- W2531 # EOL runtime; not relevant for transform tests
Expand Down
23 changes: 6 additions & 17 deletions DEVELOPMENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,16 @@ one python version locally and then have our ci (appveyor) run all supported ver

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

When adding new transform tests, we have provided a script to help generate the transform test input
and output files in the correct directory given a `template.yaml` file.
```bash
python3 bin/add_transform_test.py --template-file template.yaml
```

This script will automatically generate the input and output files. It will guarantee that the output
files have the correct AWS partition (e.g. aws-cn, aws-us-gov).
We provide a script to help generate the transform test input
and output files in the correct directory given a SAM template. For example:

For `AWS::ApiGateway::RestApi`, the script will automatically append `REGIONAL` `EndpointConfiguration`.
To disable this feature, run the following command instead.
```bash
python3 bin/add_transform_test.py --template-file template.yaml --disable-api-configuration
```

The script automatically updates hardcoded ARN partitions to match the output partition. To disable this, use:
```bash
python3 bin/add_transform_test.py --template-file template.yaml --disable-update-partition
python3 bin/add_transform_test.py --template-file template.yaml
```

Please always check the generated output is as expected. This tool does not guarantee correct output.
> **Warning**
>
> Always check the generated output is as expected. This tool does not guarantee correct output.

#### Transform failures

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fetch-schema-data:
mkdir -p .tmp

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

rm -rf .tmp/aws-cloudformation-user-guide
git clone --depth 1 https://github.com/awsdocs/aws-cloudformation-user-guide.git .tmp/aws-cloudformation-user-guide
Expand Down
52 changes: 8 additions & 44 deletions bin/add_transform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from copy import deepcopy
from pathlib import Path
from typing import Any, Dict
from unittest.mock import patch

import boto3

from samtranslator.translator.arn_generator import ArnGenerator
from samtranslator.translator.managed_policy_translator import ManagedPolicyLoader
from samtranslator.translator.transform import transform
from samtranslator.yaml_helper import yaml_parse
Expand All @@ -28,16 +28,6 @@
type=Path,
default=Path("template.yaml"),
)
parser.add_argument(
"--disable-api-configuration",
help="Disable adding REGIONAL configuration to AWS::ApiGateway::RestApi",
action="store_true",
)
parser.add_argument(
"--disable-update-partition",
help="Disable updating the partition of arn to aws-cn/aws-us-gov",
action="store_true",
)
CLI_OPTIONS = parser.parse_args()


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


def add_regional_endpoint_configuration_if_needed(template: Dict[str, Any]) -> Dict[str, Any]:
for _, resource in template["Resources"].items():
if resource["Type"] == "AWS::ApiGateway::RestApi":
properties = resource["Properties"]
if "EndpointConfiguration" not in properties:
properties["EndpointConfiguration"] = {"Types": ["REGIONAL"]}
if "Parameters" not in properties:
properties["Parameters"] = {"endpointConfigurationTypes": "REGIONAL"}

return template


def replace_aws_partition(partition: str, file_path: Path) -> None:
template = read_json_file(file_path)
updated_template = json.loads(json.dumps(template).replace("arn:aws:", f"arn:{partition}:"))
file_path.write_text(json.dumps(updated_template, indent=2), encoding="utf-8")
print(f"Transform Test output files generated {file_path}")


def generate_transform_test_output_files(input_file_path: Path, file_basename: str) -> None:
output_file_option = file_basename + ".json"

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

for partition, (region, output_path) in transform_test_output_paths.items():
# Set Boto Session Region to guarantee the same hash input as transform tests for API deployment id
ArnGenerator.BOTO_SESSION_REGION_NAME = region
# Implicit API Plugin may alter input template file, thus passing a copy here.
output_fragment = transform(deepcopy(manifest), {}, ManagedPolicyLoader(iam_client))

if not CLI_OPTIONS.disable_api_configuration and partition != "aws":
output_fragment = add_regional_endpoint_configuration_if_needed(output_fragment)

write_json_file(output_fragment, output_path)

# Update arn partition if necessary
if not CLI_OPTIONS.disable_update_partition:
replace_aws_partition(partition, output_path)
for _, (region, output_path) in transform_test_output_paths.items():
with patch("samtranslator.translator.arn_generator._get_region_from_session", return_value=region), patch(
"boto3.session.Session.region_name", region
):
# Implicit API Plugin may alter input template file, thus passing a copy here.
output_fragment = transform(deepcopy(manifest), {}, ManagedPolicyLoader(iam_client))
write_json_file(output_fragment, output_path)


def get_input_file_path() -> Path:
Expand Down
17 changes: 13 additions & 4 deletions bin/sam-translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
help="Enables verbose logging",
action="store_true",
)
parser.add_argument(
"--stdout",
help="Write transformed template to stdout instead of a file",
action="store_true",
)
cli_options = parser.parse_args()

if cli_options.verbose:
Expand Down Expand Up @@ -100,14 +105,18 @@ def package(input_file_path: Path) -> Path:
return package_output_template_file


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

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

if stdout:
print(cloud_formation_template_prettified)
return

output_file_path.write_text(cloud_formation_template_prettified, encoding="utf-8")

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

if cli_options.command == "package":
package_output_template_file = package(input_file_path)
transform_template(package_output_template_file, output_file_path)
transform_template(package_output_template_file, output_file_path, cli_options.stdout)
elif cli_options.command == "deploy":
package_output_template_file = package(input_file_path)
transform_template(package_output_template_file, output_file_path)
transform_template(package_output_template_file, output_file_path, cli_options.stdout)
deploy(output_file_path)
else:
transform_template(input_file_path, output_file_path)
transform_template(input_file_path, output_file_path, cli_options.stdout)
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")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from parameterized import parameterized

from integration.config.service_names import STATE_MACHINE_CWE_CWS
from integration.helpers.base_test import BaseTest
from integration.helpers.base_test import BaseTest, nonblocking
from integration.helpers.common_api import get_policy_statements
from integration.helpers.resource import current_region_does_not_support

Expand All @@ -12,6 +12,7 @@
current_region_does_not_support([STATE_MACHINE_CWE_CWS]),
"StateMachine CweCws is not supported in this testing region",
)
@nonblocking
class TestStateMachineWithSchedule(BaseTest):
@parameterized.expand(
[
Expand Down
1 change: 0 additions & 1 deletion integration/config/service_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
LAMBDA_URL = "LambdaUrl"
LAMBDA_ENV_VARS = "LambdaEnvVars"
EVENT_INVOKE_CONFIG = "EventInvokeConfig"
EPHEMERAL_STORAGE = "EphemeralStorage"
API_KEY = "ApiKey"
APP_SYNC = "AppSync"
SNS_FILTER_POLICY_SCOPE = "SnsFilterPolicyScope"
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"
}
]

This file was deleted.

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 was deleted.

Loading