Skip to content

Release 1.98.0 (to main) #3775

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

Merged
merged 7 commits into from
Jun 4, 2025
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
2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.97.0"
__version__ = "1.98.0"
23 changes: 19 additions & 4 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" SAM macro definitions """

import copy
import re
from contextlib import suppress
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union, cast

Expand Down Expand Up @@ -238,7 +239,6 @@ class SamFunction(SamResourceMacro):

# DeadLetterQueue
dead_letter_queue_policy_actions = {"SQS": "sqs:SendMessage", "SNS": "sns:Publish"}
#

# Conditions
conditions: Dict[str, Any] = {} # TODO: Replace `Any` with something more specific
Expand Down Expand Up @@ -325,7 +325,7 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: P
resources.append(url_permission)

self._validate_deployment_preference_and_add_update_policy(
kwargs.get("deployment_preference_collection", None),
kwargs.get("deployment_preference_collection"),
lambda_alias,
intrinsics_resolver,
cast(IntrinsicsResolver, mappings_resolver), # TODO: better handle mappings_resolver's Optional
Expand Down Expand Up @@ -1002,7 +1002,22 @@ def _construct_alias(self, name: str, function: LambdaFunction, version: LambdaV
if not name:
raise InvalidResourceException(self.logical_id, "Alias name is required to create an alias")

logical_id = f"{function.logical_id}Alias{name}"
# Validate alias name against the required pattern: (?!^[0-9]+$)([a-zA-Z0-9-_]+)
# This ensures the alias name:
# 1. Contains only alphanumeric characters, hyphens, and underscores
# 2. Is not purely numeric
ALIAS_REGEX = r"(?!^[0-9]+$)([a-zA-Z0-9\-_]+)$"
if not re.match(ALIAS_REGEX, name):
raise InvalidResourceException(
self.logical_id,
f"AutoPublishAlias name ('{name}') must contain only alphanumeric characters, hyphens, or underscores matching (?!^[0-9]+$)([a-zA-Z0-9-_]+) pattern.",
)

# Strip hyphens and underscores from the alias name for the logical ID
# This ensures the logical ID contains only alphanumeric characters
alias_alphanumeric_name = name.replace("-", "D").replace("_", "U")

logical_id = f"{function.logical_id}Alias{alias_alphanumeric_name}"
alias = LambdaAlias(logical_id=logical_id, attributes=self.get_passthrough_resource_attributes())
alias.Name = name
alias.FunctionName = function.get_runtime_attr("name")
Expand All @@ -1014,7 +1029,7 @@ def _construct_alias(self, name: str, function: LambdaFunction, version: LambdaV

def _validate_deployment_preference_and_add_update_policy( # noqa: PLR0913
self,
deployment_preference_collection: DeploymentPreferenceCollection,
deployment_preference_collection: Optional[DeploymentPreferenceCollection],
lambda_alias: Optional[LambdaAlias],
intrinsics_resolver: IntrinsicsResolver,
mappings_resolver: IntrinsicsResolver,
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/region_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def is_apigw_edge_configuration_supported(cls) -> bool:
:return: True, if API Gateway does not support Edge configuration
"""
partition = ArnGenerator.get_partition_name()
if partition.startswith("aws-iso") or partition in ["aws-us-gov", "aws-cn"]:
if partition.startswith("aws-iso") or partition in ["aws-us-gov", "aws-cn", "aws-eusc"]:
return False
return True

Expand Down
186 changes: 93 additions & 93 deletions samtranslator/schema/schema.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions samtranslator/translator/arn_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def _region_to_partition(region: str) -> str:
"us-gov": "aws-us-gov",
"eu-isoe": "aws-iso-e",
"us-isof": "aws-iso-f",
"eusc-": "aws-eusc",
}
for key, value in region_to_partition_map.items():
if region_string.startswith(key):
Expand Down
613 changes: 456 additions & 157 deletions schema_source/cloudformation-docs.json

Large diffs are not rendered by default.

186 changes: 93 additions & 93 deletions schema_source/cloudformation.schema.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
# Using an invalid alias name with special characters that can't be properly transformed
AutoPublishAlias: invalid*alias@name
54 changes: 54 additions & 0 deletions tests/translator/input/function_with_alias_valid_names.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Resources:
FunctionAliasNameCamelCase:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
AutoPublishAlias: camelCaseName
VersionDescription: sam-testing

FunctionAliasNameUpperCase:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
AutoPublishAlias: UPPERCASE
VersionDescription: sam-testing

FunctionAliasNameLowerCase:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
AutoPublishAlias: lowercase
VersionDescription: sam-testing

FunctionAliasNameUnderscore:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
AutoPublishAlias: _underscore_name_
VersionDescription: sam-testing

FunctionAliasNameDash:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
AutoPublishAlias: underscore-name
VersionDescription: sam-testing

FunctionAliasNameMix:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
AutoPublishAlias: underScoreNAME_with-dash-01234
VersionDescription: sam-testing
Loading