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.92.0 (to main) #3652

Closed
wants to merge 11 commits into from
4 changes: 2 additions & 2 deletions DEVELOPMENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ We format our code using [Black](https://github.com/python/black) and verify the
during PR checks. Black will be installed automatically with `make init`.

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

##### (Workaround) Integrating Black directly in your favorite IDE
Since black is installed in virtualenv, when you follow [this instruction](https://black.readthedocs.io/en/stable/editor_integration.html), `which black` might give you this
Since black is installed in virtualenv, when you follow [this instruction](https://black.readthedocs.io/en/stable/integrations/editors.html), `which black` might give you this

```bash
(sam38) $ where black
Expand Down
13 changes: 10 additions & 3 deletions bin/add_transform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ def get_input_file_path() -> Path:


def copy_input_file_to_transform_test_dir(input_file_path: Path, transform_test_input_path: Path) -> None:
shutil.copyfile(input_file_path, transform_test_input_path)
print(f"Transform Test input file generated {transform_test_input_path}")
try:
shutil.copyfile(input_file_path, transform_test_input_path)
print(f"Transform Test input file generated {transform_test_input_path}")
except shutil.SameFileError:
print(f"Source and destination are the same file: {input_file_path}")
except Exception as e:
raise e


def verify_input_template(input_file_path: Path) -> None:
Expand Down Expand Up @@ -99,7 +104,9 @@ def main() -> None:
verify_input_template(input_file_path)

transform_test_input_path = TRANSFORM_TEST_DIR / "input" / (file_basename + ".yaml")
copy_input_file_to_transform_test_dir(input_file_path, transform_test_input_path)
# check if the template is not already in the transform test input dir
if input_file_path != transform_test_input_path:
copy_input_file_to_transform_test_dir(input_file_path, transform_test_input_path)

generate_transform_test_output_files(transform_test_input_path, file_basename)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: hello.handler
Runtime: python3.8
Runtime: python3.11
Policies:

- SQSPollerPolicy:
Expand Down Expand Up @@ -123,7 +123,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: hello.handler
Runtime: python3.8
Runtime: python3.11
Policies:

- SESEmailTemplateCrudPolicy: {}
Expand Down Expand Up @@ -187,7 +187,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: hello.handler
Runtime: python3.8
Runtime: python3.11
Policies:
- ElasticMapReduceModifyInstanceFleetPolicy:
ClusterId: name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Resources:
InlineCode: |
print("hello")
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
Events:
API3:
Type: Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
TriggerFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: python3.8
Runtime: python3.11
Handler: index.handler
InlineCode: |
import boto3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Resources:
Role:
Fn::GetAtt: LambdaRole.Arn
Handler: lambda_function.lambda_handler
Runtime: python3.8
Runtime: python3.11
Timeout: 15
CodeUri: ${codeuri}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: index.handler
Runtime: python3.8
Runtime: python3.11

AutoPublishAlias: Live

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: index.handler
Runtime: python3.8
Runtime: python3.11

AutoPublishAlias: Live

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
AutoPublishAlias: Live
DeploymentPreference:
Type: Canary10Percent5Minutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
AutoPublishAlias: Live

DeploymentRole:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
InlineCode: |
def handler(event, context):
return {'body': 'Hello World!', 'statusCode': 200}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
InlineCode: |
def handler(event, context):
return {'body': 'Hello World!', 'statusCode': 200}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
InlineCode: |
def handler(event, context):
return {'body': 'Hello World!', 'statusCode': 200}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: hello.handler
Runtime: python3.8
Runtime: python3.11
Policies:
- SQSPollerPolicy:
QueueName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: hello.handler
Runtime: python3.8
Runtime: python3.11
AutoPublishAlias: Live

MyOtherFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ${codeuri}
Runtime: python3.8
Runtime: python3.11
Handler: hello.handler
Environment:
Variables:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
InlineCode: |
def handler(event, context):
return {'body': 'Hello World!', 'statusCode': 200}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
InlineCode: |
def handler(event, context):
return {'body': 'Hello World!', 'statusCode': 200}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Resources:
InlineCode: |
def handler(event, context):
print("Hello, world!")
Runtime: python3.8
Runtime: python3.11
Architectures:
- x86_64
Events:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: hello.handler
Runtime: python3.8
Runtime: python3.11

MyQueue:
Type: AWS::SQS::Queue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
AutoPublishAlias: live
InlineCode: |
import json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
AutoPublishAlias: live
InlineCode: |
def handler(event, context):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: hello.handler
Runtime: python3.8
Runtime: python3.11
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery3Minutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Resources:
Properties:
CodeUri: ${codeuri}
Handler: hello.handler
Runtime: python3.8
Runtime: python3.11
RolePath: /foo/bar/
Metadata:
SamTransformTest: true
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Resources:
print(event)
return "do nothing"
Handler: index.handler
Runtime: python3.8
Runtime: python3.11
Post:
Type: AWS::Serverless::StateMachine
Properties:
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.91.0"
__version__ = "1.92.0"
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class Properties(BaseModel):
Type: Optional[PassThroughProp] = properties("Type")
AutoPublishAlias: Optional[PassThroughProp]
DeploymentPreference: Optional[PassThroughProp]
UseAliasAsEventTarget: Optional[bool]


class Resource(ResourceAttributes):
Expand Down
3 changes: 3 additions & 0 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,7 @@ class SamStateMachine(SamResourceMacro):
"PermissionsBoundary": PropertyType(False, IS_STR),
"AutoPublishAlias": PassThroughProperty(False),
"DeploymentPreference": MutatedPassThroughProperty(False),
"UseAliasAsEventTarget": Property(False, IS_BOOL),
}

Definition: Optional[Dict[str, Any]]
Expand All @@ -1799,6 +1800,7 @@ class SamStateMachine(SamResourceMacro):
PermissionsBoundary: Optional[Intrinsicable[str]]
AutoPublishAlias: Optional[PassThrough]
DeploymentPreference: Optional[PassThrough]
UseAliasAsEventTarget: Optional[bool]

event_resolver = ResourceTypeResolver(
samtranslator.model.stepfunctions.events,
Expand Down Expand Up @@ -1837,6 +1839,7 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def]
get_managed_policy_map=get_managed_policy_map,
auto_publish_alias=self.AutoPublishAlias,
deployment_preference=self.DeploymentPreference,
use_alias_as_event_target=self.UseAliasAsEventTarget,
)

generated_resources = state_machine_generator.to_cloudformation()
Expand Down
16 changes: 15 additions & 1 deletion samtranslator/model/stepfunctions/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__( # type: ignore[no-untyped-def] # noqa: PLR0913
get_managed_policy_map=None,
auto_publish_alias=None,
deployment_preference=None,
use_alias_as_event_target=None,
):
"""
Constructs an State Machine Generator class that generates a State Machine resource
Expand Down Expand Up @@ -81,6 +82,7 @@ def __init__( # type: ignore[no-untyped-def] # noqa: PLR0913
:param passthrough_resource_attributes: Attributes such as `Condition` that are added to derived resources
:param auto_publish_alias: Name of the state machine alias to automatically create and update
:deployment_preference: Settings to enable gradual state machine deployments
:param use_alias_as_event_target: Whether to use the state machine alias as the event target
"""
self.logical_id = logical_id
self.depends_on = depends_on
Expand Down Expand Up @@ -110,6 +112,7 @@ def __init__( # type: ignore[no-untyped-def] # noqa: PLR0913
self.get_managed_policy_map = get_managed_policy_map
self.auto_publish_alias = auto_publish_alias
self.deployment_preference = deployment_preference
self.use_alias_as_event_target = use_alias_as_event_target

@cw_timer(prefix="Generator", name="StateMachine")
def to_cloudformation(self): # type: ignore[no-untyped-def]
Expand Down Expand Up @@ -300,6 +303,8 @@ def _construct_alias(self, version: StepFunctionsStateMachineVersion) -> StepFun
deployment_preference["StateMachineVersionArn"] = state_machine_version_arn
state_machine_alias.DeploymentPreference = deployment_preference

self.state_machine_alias = state_machine_alias

return state_machine_alias

def _generate_managed_traffic_shifting_resources(
Expand All @@ -310,6 +315,10 @@ def _generate_managed_traffic_shifting_resources(
:returns: a list containing the state machine's version and alias resources
:rtype: list
"""
if not self.auto_publish_alias and self.use_alias_as_event_target:
raise InvalidResourceException(
self.logical_id, "'UseAliasAsEventTarget' requires 'AutoPublishAlias' property to be specified."
)
if not self.auto_publish_alias and not self.deployment_preference:
return []
if not self.auto_publish_alias and self.deployment_preference:
Expand Down Expand Up @@ -341,7 +350,12 @@ def _generate_event_resources(self) -> List[Dict[str, Any]]:
kwargs[name] = resource
except (TypeError, AttributeError) as e:
raise InvalidEventException(logical_id, str(e)) from e
resources += eventsource.to_cloudformation(resource=self.state_machine, **kwargs)
target_resource = (
(self.state_machine_alias or self.state_machine)
if self.use_alias_as_event_target
else self.state_machine
)
resources += eventsource.to_cloudformation(resource=target_resource, **kwargs)

return resources

Expand Down
Loading
Loading