Skip to content

Commit b5a19c1

Browse files
committed
Merge branch 'develop' into tmp/1677620262/main
2 parents 1b96427 + 2ba5048 commit b5a19c1

File tree

392 files changed

+39074
-8659
lines changed

Some content is hidden

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

392 files changed

+39074
-8659
lines changed

.cfnlintrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ ignore_templates:
120120
- tests/translator/output/**/state_machine_with_schedule_dlq_retry_policy.json
121121
- tests/translator/output/**/globals_for_function.json # RuntimeManagementConfig
122122
- tests/translator/output/**/function_with_runtime_config.json # RuntimeManagementConfig
123+
- tests/translator/output/**/managed_policies_minimal.json # Intentionally has non-existent managed policy name
123124
ignore_checks:
124125
- E2531 # Deprecated runtime; not relevant for transform tests
125126
- W2531 # EOL runtime; not relevant for transform tests

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ branch = True
33
omit =
44
# Schema tested by `make check-black`
55
samtranslator/schema/*
6+
samtranslator/internal/schema_source/*
67
[report]
78
exclude_lines =
89
pragma: no cover

DEVELOPMENT_GUIDE.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ eval "$(pyenv virtualenv-init -)"
5959
We format our code using [Black](https://github.com/python/black) and verify the source code is black compliant
6060
during PR checks. Black will be installed automatically with `make init`.
6161

62-
After installing, you can run our formatting through our Makefile by `make black` or integrating Black directly in your favorite IDE (instructions
62+
After installing, you can run our formatting through our Makefile by `make format` or integrating Black directly in your favorite IDE (instructions
6363
can be found [here](https://black.readthedocs.io/en/stable/editor_integration.html))
6464

6565
##### (Workaround) Integrating Black directly in your favorite IDE
@@ -158,11 +158,16 @@ Integration tests are covered in detail in the [INTEGRATION_TESTS.md file](INTEG
158158

159159
## Development guidelines
160160

161-
1. **Do not resolve [intrinsic functions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html).** Adding [`AWS::LanguageExtensions`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-languageextension-transform.html) before the `AWS::Serverless-2016-10-31` transform resolves most of them (see https://github.com/aws/serverless-application-model/issues/2533). For new properties, use [`Property`](https://github.com/aws/serverless-application-model/blob/c5830b63857f52e540fec13b29f029458edc539a/samtranslator/model/__init__.py#L36-L45) or [`PassThroughProperty`](https://github.com/aws/serverless-application-model/blob/dd79f535500158baa8e367f081d6a12113497e45/samtranslator/model/__init__.py#L48-L56) instead of [`PropertyType`](https://github.com/aws/serverless-application-model/blob/c39c2807bbf327255de8abed8b8150b18c60f053/samtranslator/model/__init__.py#L13-L33).
161+
1. **Do not resolve [intrinsic functions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html).** Adding [`AWS::LanguageExtensions`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-languageextension-transform.html) before the `AWS::Serverless-2016-10-31` transform resolves most of them (see https://github.com/aws/serverless-application-model/issues/2533).
162162
2. **Do not break backward compatibility.** A specific SAM template should always transform into the same CloudFormation template. A template that has previously deployed successfully should continue to do so. Do not change logical IDs. Add opt-in properties for breaking changes. There are some exceptions, such as changes that do not impact resources (e.g. [`Metadata`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html)) or abstractions that can by design change over time.
163163
3. **Stick as close as possible to the underlying CloudFormation properties.** This includes both property names and values. This ensures we can pass values to CloudFormation and let it handle any intrinsic functions. In some cases, it also allows us to pass all properties as-is to a resource, which means customers can always use the newest properties, and we don’t spend effort maintaining a duplicate set of properties.
164164
4. **Only validate what’s necessary.** Do not validate properties if they’re passed directly to the underlying CloudFormation resource.
165165
5. **Add [type hints](https://peps.python.org/pep-0484/) to new code.** Strict typing was enabled in https://github.com/aws/serverless-application-model/pull/2558 by sprinkling [`# type: ignore`](https://peps.python.org/pep-0484/#compatibility-with-other-uses-of-function-annotations) across the existing code. Don't do that for new code. Avoid `# type: ignore`s at all cost. Instead, add types to new functions, and ideally add types to existing code it uses as well.
166+
6. **Do not use [`PropertyType`](https://github.com/aws/serverless-application-model/blob/c39c2807bbf327255de8abed8b8150b18c60f053/samtranslator/model/__init__.py#L13-L33) for new [`Resource`](https://github.com/aws/serverless-application-model/blob/13604cd2d9671cd6e774e5bfd610a03d82a08d76/samtranslator/model/__init__.py#L68) properties.**
167+
168+
For new properties of SAM resources, use [`Property`](https://github.com/aws/serverless-application-model/blob/c5830b63857f52e540fec13b29f029458edc539a/samtranslator/model/__init__.py#L36-L45) or [`PassThroughProperty`](https://github.com/aws/serverless-application-model/blob/dd79f535500158baa8e367f081d6a12113497e45/samtranslator/model/__init__.py#L48-L56) instead of [`PropertyType`](https://github.com/aws/serverless-application-model/blob/c39c2807bbf327255de8abed8b8150b18c60f053/samtranslator/model/__init__.py#L13-L33). This avoids [sneaky bugs](https://github.com/aws/serverless-application-model/pull/2495#discussion_r976715242) and ensures valid templates do not cause transform failures.
169+
170+
For new properties of CloudFormation resources, use [`GeneratedProperty`](https://github.com/aws/serverless-application-model/blob/79452f69bc1fcf918b8625c2f9005c74ab874801/samtranslator/model/__init__.py#L74-L82). It performs no runtime validation, reducing the risk of valid values causing transform failures.
166171

167172
Code conventions
168173
----------------

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ recursive-include samtranslator/validator/sam_schema *.json
88
include samtranslator/policy_templates_data/policy_templates.json
99
include samtranslator/policy_templates_data/schema.json
1010
include samtranslator/model/connector_profiles/profiles.json
11+
include samtranslator/internal/data/aws_managed_policies.json
12+
include samtranslator/internal/schema_source/sam-docs.json
1113
include README.md
1214
include THIRD_PARTY_LICENSES
1315

Makefile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,37 @@ test-cov-report:
1717
integ-test:
1818
pytest --no-cov integration/
1919

20-
black:
20+
format:
2121
black setup.py samtranslator tests integration bin schema_source
22+
bin/transform-test-error-json-format.py --write tests/translator/output/error_*.json
2223
bin/json-format.py --write tests integration samtranslator/policy_templates_data
2324
bin/yaml-format.py --write tests
2425
bin/yaml-format.py --write integration --add-test-metadata
2526

26-
black-check:
27+
black:
28+
$(warning `make black` is deprecated, please use `make format`)
29+
# sleep for 5 seconds so the message can be seen.
30+
sleep 5
31+
make format
32+
33+
format-check:
2734
# Checking latest schema was generated (run `make schema` if this fails)
2835
mkdir -p .tmp
29-
python -m schema_source.schema --sam-schema .tmp/sam.schema.json --cfn-schema schema_source/cloudformation.schema.json --unified-schema .tmp/schema.json
36+
python -m samtranslator.internal.schema_source.schema --sam-schema .tmp/sam.schema.json --cfn-schema schema_source/cloudformation.schema.json --unified-schema .tmp/schema.json
3037
diff -u schema_source/sam.schema.json .tmp/sam.schema.json
3138
diff -u samtranslator/schema/schema.json .tmp/schema.json
3239
black --check setup.py samtranslator tests integration bin schema_source
40+
bin/transform-test-error-json-format.py --check tests/translator/output/error_*.json
3341
bin/json-format.py --check tests integration samtranslator/policy_templates_data
3442
bin/yaml-format.py --check tests
3543
bin/yaml-format.py --check integration --add-test-metadata
3644

45+
black-check:
46+
$(warning `make black-check` is deprecated, please use `make format-check`)
47+
# sleep for 5 seconds so the message can be seen.
48+
sleep 5
49+
make format-check
50+
3751
lint:
3852
ruff samtranslator bin schema_source integration tests
3953
# mypy performs type check
@@ -60,14 +74,14 @@ fetch-schema-data:
6074

6175
update-schema-data:
6276
# Parse docs
63-
bin/parse_docs.py .tmp/aws-sam-developer-guide/doc_source > schema_source/docs.json
77+
bin/parse_docs.py .tmp/aws-sam-developer-guide/doc_source > samtranslator/internal/schema_source/sam-docs.json
6478
bin/parse_docs.py --cfn .tmp/aws-cloudformation-user-guide/doc_source > schema_source/cloudformation-docs.json
6579

6680
# Add CloudFormation docs to CloudFormation schema
6781
python bin/add_docs_cfn_schema.py --schema .tmp/cloudformation.schema.json --docs schema_source/cloudformation-docs.json > schema_source/cloudformation.schema.json
6882

6983
schema:
70-
python -m schema_source.schema --sam-schema schema_source/sam.schema.json --cfn-schema schema_source/cloudformation.schema.json --unified-schema samtranslator/schema/schema.json
84+
python -m samtranslator.internal.schema_source.schema --sam-schema schema_source/sam.schema.json --cfn-schema schema_source/cloudformation.schema.json --unified-schema samtranslator/schema/schema.json
7185

7286
# Update all schema data and schemas
7387
schema-all: fetch-schema-data update-schema-data schema
@@ -76,7 +90,7 @@ schema-all: fetch-schema-data update-schema-data schema
7690
dev: test
7791

7892
# Verifications to run before sending a pull request
79-
pr: black-check lint init dev
93+
pr: format-check lint init dev
8094

8195
clean:
8296
rm -rf .tmp

bin/parse_docs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ def main() -> None:
8989
if args.cfn and not re.match(r"^\w+::\w+::\w+( \w+)?$", title):
9090
continue
9191
page = title if args.cfn else path.stem
92-
for name, description in parse(text):
92+
for name, raw_description in parse(text):
9393
if page not in props:
9494
props[page] = {}
95-
description = remove_first_line(description) # Remove property name; already in the schema title
95+
description = remove_first_line(raw_description) # Remove property name; already in the schema title
9696
description = fix_markdown_code_link(description)
9797
prefix = (
9898
"https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/"

bin/sam-translate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def transform_template(input_file_path, output_file_path): # type: ignore[no-un
106106
sam_template = yaml_parse(f) # type: ignore[no-untyped-call]
107107

108108
try:
109-
cloud_formation_template = transform(sam_template, {}, ManagedPolicyLoader(iam_client)) # type: ignore[no-untyped-call]
109+
cloud_formation_template = transform(sam_template, {}, ManagedPolicyLoader(iam_client))
110110
cloud_formation_template_prettified = json.dumps(cloud_formation_template, indent=1)
111111

112112
with open(output_file_path, "w") as f:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python
2+
"""
3+
Transform test error JSON file formatter (without prettier).
4+
5+
It makes error json easier to review by breaking down "errorMessage"
6+
into list of strings (delimiter: ". ").
7+
"""
8+
import os
9+
import sys
10+
11+
from typing_extensions import Final
12+
13+
my_path = os.path.dirname(os.path.abspath(__file__))
14+
sys.path.insert(0, my_path + "/..")
15+
16+
import json
17+
from typing import Type
18+
19+
from bin._file_formatter import FileFormatter
20+
21+
22+
class TransformTestErrorJSONFormatter(FileFormatter):
23+
_ERROR_MESSAGE_KEY: Final[str] = "errorMessage"
24+
_BREAKDOWN_ERROR_MESSAGE_KEY: Final[str] = "_autoGeneratedBreakdownErrorMessage"
25+
_DELIMITER: Final[str] = ". "
26+
27+
@staticmethod
28+
def description() -> str:
29+
return "Transform test error JSON file formatter"
30+
31+
def format_str(self, input_str: str) -> str:
32+
"""
33+
It makes error json easier to review by breaking down "errorMessage"
34+
into list of strings (delimiter: ". ").
35+
"""
36+
obj = json.loads(input_str)
37+
error_message = obj.get(self._ERROR_MESSAGE_KEY)
38+
if isinstance(error_message, str):
39+
tokens = error_message.split(self._DELIMITER)
40+
obj[self._BREAKDOWN_ERROR_MESSAGE_KEY] = [
41+
token if index == len(tokens) - 1 else token + self._DELIMITER for index, token in enumerate(tokens)
42+
]
43+
return json.dumps(obj, indent=2, sort_keys=True) + "\n"
44+
45+
@staticmethod
46+
def decode_exception() -> Type[Exception]:
47+
return json.JSONDecodeError
48+
49+
@staticmethod
50+
def file_extension() -> str:
51+
return ".json"
52+
53+
54+
if __name__ == "__main__":
55+
TransformTestErrorJSONFormatter.main()

docs/globals.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Currently, the following resources and properties are being supported:
8181
Auth:
8282
Name:
8383
DefinitionUri:
84+
MergeDefinitions:
8485
CacheClusterEnabled:
8586
CacheClusterSize:
8687
Variables:

integration/combination/test_connectors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def tearDown(self):
2626

2727
@parameterized.expand(
2828
[
29+
("combination/connector_appsync_to_table",),
2930
("combination/connector_function_to_function",),
3031
("combination/connector_restapi_to_function",),
3132
("combination/connector_httpapi_to_function",),

0 commit comments

Comments
 (0)