Skip to content

Commit 556c315

Browse files
committed
feat: Add Type S3Bucket to DestinationConfig
1 parent 8878af7 commit 556c315

19 files changed

+1472
-30
lines changed

.cfnlintrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ ignore_templates:
131131
- 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]
132132
- 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]
133133
- tests/translator/output/**/function_with_recursive_loop.json # Invalid Property Resources/RecursiveLoopParameterFunction/Properties/RecursiveLoop
134+
- tests/translator/output/**/function_with_sourcekmskeyarn.json # Invalid Property Resources/SourceKMSKeyArnParameterFunction/Properties/SourceKMSKeyArn
134135
- tests/translator/output/**/function_with_tracing.json # Obsolete DependsOn on resource
135136
- tests/translator/output/**/api_with_propagate_tags.json # TODO: Intentional error transform tests. Will be updated.
136137
- tests/translator/output/**/function_with_intrinsics_resource_attribute.json # CFN now supports intrinsics in DeletionPolicy

samtranslator/internal/schema_source/aws_serverless_function.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ class DeadLetterQueue(BaseModel):
105105

106106
class EventInvokeOnFailure(BaseModel):
107107
Destination: Optional[SamIntrinsicable[str]] = eventinvokeonfailure("Destination")
108-
Type: Optional[Literal["SQS", "SNS", "Lambda", "EventBridge"]] = eventinvokeonfailure("Type")
108+
Type: Optional[Literal["SQS", "SNS", "Lambda", "EventBridge", "S3Bucket"]] = eventinvokeonfailure("Type")
109109

110110

111111
class EventInvokeOnSuccess(BaseModel):
112112
Destination: Optional[SamIntrinsicable[str]] = eventinvokeonsuccess("Destination")
113-
Type: Optional[Literal["SQS", "SNS", "Lambda", "EventBridge"]] = eventinvokeonsuccess("Type")
113+
Type: Optional[Literal["SQS", "SNS", "Lambda", "EventBridge", "S3Bucket"]] = eventinvokeonsuccess("Type")
114114

115115

116116
class EventInvokeDestinationConfig(BaseModel):
@@ -516,6 +516,7 @@ class ScheduleV2Event(BaseModel):
516516
RuntimeManagementConfig = Optional[PassThroughProp] # TODO: check the type
517517
LoggingConfig = Optional[PassThroughProp] # TODO: add documentation
518518
RecursiveLoop = Optional[PassThroughProp]
519+
SourceKMSKeyArn = Optional[PassThroughProp]
519520

520521

521522
class Properties(BaseModel):
@@ -643,6 +644,7 @@ class Properties(BaseModel):
643644
VpcConfig: Optional[VpcConfig] = prop("VpcConfig")
644645
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
645646
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
647+
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
646648

647649

648650
class Globals(BaseModel):
@@ -702,6 +704,7 @@ class Globals(BaseModel):
702704
RuntimeManagementConfig: Optional[RuntimeManagementConfig] = prop("RuntimeManagementConfig")
703705
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
704706
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
707+
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
705708

706709

707710
class Resource(ResourceAttributes):

samtranslator/model/sam_resources.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" SAM macro definitions """
1+
""" SAM macro definitions """
22

33
import copy
44
from contextlib import suppress
@@ -181,6 +181,7 @@ class SamFunction(SamResourceMacro):
181181
"RuntimeManagementConfig": PassThroughProperty(False),
182182
"LoggingConfig": PassThroughProperty(False),
183183
"RecursiveLoop": PassThroughProperty(False),
184+
"SourceKMSKeyArn": PassThroughProperty(False),
184185
}
185186

186187
FunctionName: Optional[Intrinsicable[str]]
@@ -224,6 +225,7 @@ class SamFunction(SamResourceMacro):
224225
FunctionUrlConfig: Optional[Dict[str, Any]]
225226
LoggingConfig: Optional[Dict[str, Any]]
226227
RecursiveLoop: Optional[str]
228+
SourceKMSKeyArn: Optional[str]
227229

228230
event_resolver = ResourceTypeResolver(
229231
samtranslator.model.eventsources,
@@ -439,7 +441,7 @@ def _validate_and_inject_resource(
439441
ARN property, so to handle conditional ifs we have to inject if conditions in the auto created
440442
SQS/SNS resources as well as in the policy documents.
441443
"""
442-
accepted_types_list = ["SQS", "SNS", "EventBridge", "Lambda"]
444+
accepted_types_list = ["SQS", "SNS", "EventBridge", "Lambda", "S3Bucket"]
443445
auto_inject_list = ["SQS", "SNS"]
444446
resource: Optional[Union[SNSTopic, SQSQueue]] = None
445447
policy = {}
@@ -630,6 +632,8 @@ def _add_event_invoke_managed_policy(
630632
return IAMRolePolicies.event_bus_put_events_role_policy(dest_arn, logical_id)
631633
if _type == "Lambda":
632634
return IAMRolePolicies.lambda_invoke_function_role_policy(dest_arn, logical_id)
635+
if _type == "S3Bucket":
636+
return IAMRolePolicies.s3_send_event_payload_role_policy(dest_arn, logical_id)
633637
return {}
634638

635639
def _construct_role(
@@ -885,7 +889,10 @@ def _construct_inline_code(*args: Any, **kwargs: Dict[str, Any]) -> Dict[str, An
885889
else:
886890
raise InvalidResourceException(self.logical_id, "Either 'InlineCode' or 'CodeUri' must be set.")
887891
dispatch_function: Callable[..., Dict[str, Any]] = artifact_dispatch[filtered_key]
888-
return dispatch_function(artifacts[filtered_key], self.logical_id, filtered_key)
892+
code_dict = dispatch_function(artifacts[filtered_key], self.logical_id, filtered_key)
893+
if self.SourceKMSKeyArn and packagetype == ZIP:
894+
code_dict["SourceKMSKeyArn"] = self.SourceKMSKeyArn
895+
return code_dict
889896

890897
def _construct_version( # noqa: PLR0912
891898
self,

samtranslator/plugins/globals/globals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Globals:
5555
"RuntimeManagementConfig",
5656
"LoggingConfig",
5757
"RecursiveLoop",
58+
"SourceKMSKeyArn",
5859
],
5960
# Everything except
6061
# DefinitionBody: because its hard to reason about merge of Swagger dictionaries
@@ -100,7 +101,7 @@ class Globals:
100101
}
101102
# unreleased_properties *must be* part of supported_properties too
102103
unreleased_properties: Dict[str, List[str]] = {
103-
SamResourceType.Function.value: ["RuntimeManagementConfig", "RecursiveLoop"],
104+
SamResourceType.Function.value: ["RuntimeManagementConfig", "RecursiveLoop", "SourceKMSKeyArn"],
104105
}
105106

106107
def __init__(self, template: Dict[str, Any]) -> None:

samtranslator/schema/schema.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274993,7 +274993,8 @@
274993274993
"SQS",
274994274994
"SNS",
274995274995
"Lambda",
274996-
"EventBridge"
274996+
"EventBridge",
274997+
"S3Bucket"
274997274998
],
274998274999
"markdownDescription": "Type of the resource referenced in the destination\\. Supported types are `SQS`, `SNS`, `Lambda`, and `EventBridge`\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent\\. \n*Additional notes*: If the type is SQS/SNS and the `Destination` property is left blank, then the SQS/SNS resource is auto generated by SAM\\. To reference the resource, use `<function-logical-id>.DestinationQueue` for SQS or `<function-logical-id>.DestinationTopic` for SNS\\. If the type is Lambda/EventBridge, `Destination` is required\\.",
274999275000
"title": "Type",
@@ -275023,7 +275024,8 @@
275023275024
"SQS",
275024275025
"SNS",
275025275026
"Lambda",
275026-
"EventBridge"
275027+
"EventBridge",
275028+
"S3Bucket"
275027275029
],
275028275030
"markdownDescription": "Type of the resource referenced in the destination\\. Supported types are `SQS`, `SNS`, `Lambda`, and `EventBridge`\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent\\. \n*Additional notes*: If the type is SQS/SNS and the `Destination` property is left blank, then the SQS/SNS resource is auto generated by SAM\\. To reference the resource, use `<function-logical-id>.DestinationQueue` for SQS or `<function-logical-id>.DestinationTopic` for SNS\\. If the type is Lambda/EventBridge, `Destination` is required\\.",
275029275031
"title": "Type",
@@ -278794,6 +278796,9 @@
278794278796
"markdownDescription": "Create a snapshot of any new Lambda function version\\. A snapshot is a cached state of your initialized function, including all of its dependencies\\. The function is initialized just once and the cached state is reused for all future invocations, improving application performance by reducing the number of times your function must be initialized\\. To learn more, see [Improving startup performance with Lambda SnapStart](https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html) in the *AWS Lambda Developer Guide*\\. \n*Type*: [SnapStart](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`SnapStart`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html) property of an `AWS::Lambda::Function` resource\\.",
278795278797
"title": "SnapStart"
278796278798
},
278799+
"SourceKMSKeyArn": {
278800+
"$ref": "#/definitions/PassThroughProp"
278801+
},
278797278802
"Tags": {
278798278803
"markdownDescription": "A map \\(string to string\\) that specifies the tags added to this function\\. For details about valid keys and values for tags, see [Tag Key and Value Requirements](https://docs.aws.amazon.com/lambda/latest/dg/configuration-tags.html#configuration-tags-restrictions) in the *AWS Lambda Developer Guide*\\. \nWhen the stack is created, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\. \n*Type*: Map \n*Required*: No \n*AWS CloudFormation compatibility*: This property is similar to the [`Tags`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-tags) property of an `AWS::Lambda::Function` resource\\. The `Tags` property in AWS SAM consists of key\\-value pairs \\(whereas in AWS CloudFormation this property consists of a list of `Tag` objects\\)\\. Also, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\.",
278799278804
"title": "Tags",
@@ -279188,6 +279193,9 @@
279188279193
"markdownDescription": "Create a snapshot of any new Lambda function version\\. A snapshot is a cached state of your initialized function, including all of its dependencies\\. The function is initialized just once and the cached state is reused for all future invocations, improving application performance by reducing the number of times your function must be initialized\\. To learn more, see [Improving startup performance with Lambda SnapStart](https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html) in the *AWS Lambda Developer Guide*\\. \n*Type*: [SnapStart](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`SnapStart`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html) property of an `AWS::Lambda::Function` resource\\.",
279189279194
"title": "SnapStart"
279190279195
},
279196+
"SourceKMSKeyArn": {
279197+
"$ref": "#/definitions/PassThroughProp"
279198+
},
279191279199
"Tags": {
279192279200
"markdownDescription": "A map \\(string to string\\) that specifies the tags added to this function\\. For details about valid keys and values for tags, see [Tag Key and Value Requirements](https://docs.aws.amazon.com/lambda/latest/dg/configuration-tags.html#configuration-tags-restrictions) in the *AWS Lambda Developer Guide*\\. \nWhen the stack is created, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\. \n*Type*: Map \n*Required*: No \n*AWS CloudFormation compatibility*: This property is similar to the [`Tags`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-tags) property of an `AWS::Lambda::Function` resource\\. The `Tags` property in AWS SAM consists of key\\-value pairs \\(whereas in AWS CloudFormation this property consists of a list of `Tag` objects\\)\\. Also, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\.",
279193279201
"title": "Tags",

schema_source/sam.schema.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,8 @@
12601260
"SQS",
12611261
"SNS",
12621262
"Lambda",
1263-
"EventBridge"
1263+
"EventBridge",
1264+
"S3Bucket"
12641265
],
12651266
"markdownDescription": "Type of the resource referenced in the destination\\. Supported types are `SQS`, `SNS`, `Lambda`, and `EventBridge`\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent\\. \n*Additional notes*: If the type is SQS/SNS and the `Destination` property is left blank, then the SQS/SNS resource is auto generated by SAM\\. To reference the resource, use `<function-logical-id>.DestinationQueue` for SQS or `<function-logical-id>.DestinationTopic` for SNS\\. If the type is Lambda/EventBridge, `Destination` is required\\.",
12661267
"title": "Type",
@@ -1290,7 +1291,8 @@
12901291
"SQS",
12911292
"SNS",
12921293
"Lambda",
1293-
"EventBridge"
1294+
"EventBridge",
1295+
"S3Bucket"
12941296
],
12951297
"markdownDescription": "Type of the resource referenced in the destination\\. Supported types are `SQS`, `SNS`, `Lambda`, and `EventBridge`\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent\\. \n*Additional notes*: If the type is SQS/SNS and the `Destination` property is left blank, then the SQS/SNS resource is auto generated by SAM\\. To reference the resource, use `<function-logical-id>.DestinationQueue` for SQS or `<function-logical-id>.DestinationTopic` for SNS\\. If the type is Lambda/EventBridge, `Destination` is required\\.",
12961298
"title": "Type",
@@ -5537,6 +5539,9 @@
55375539
"markdownDescription": "Create a snapshot of any new Lambda function version\\. A snapshot is a cached state of your initialized function, including all of its dependencies\\. The function is initialized just once and the cached state is reused for all future invocations, improving application performance by reducing the number of times your function must be initialized\\. To learn more, see [Improving startup performance with Lambda SnapStart](https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html) in the *AWS Lambda Developer Guide*\\. \n*Type*: [SnapStart](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`SnapStart`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html) property of an `AWS::Lambda::Function` resource\\.",
55385540
"title": "SnapStart"
55395541
},
5542+
"SourceKMSKeyArn": {
5543+
"$ref": "#/definitions/PassThroughProp"
5544+
},
55405545
"Tags": {
55415546
"markdownDescription": "A map \\(string to string\\) that specifies the tags added to this function\\. For details about valid keys and values for tags, see [Tag Key and Value Requirements](https://docs.aws.amazon.com/lambda/latest/dg/configuration-tags.html#configuration-tags-restrictions) in the *AWS Lambda Developer Guide*\\. \nWhen the stack is created, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\. \n*Type*: Map \n*Required*: No \n*AWS CloudFormation compatibility*: This property is similar to the [`Tags`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-tags) property of an `AWS::Lambda::Function` resource\\. The `Tags` property in AWS SAM consists of key\\-value pairs \\(whereas in AWS CloudFormation this property consists of a list of `Tag` objects\\)\\. Also, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\.",
55425547
"title": "Tags",
@@ -6122,6 +6127,9 @@
61226127
"markdownDescription": "Create a snapshot of any new Lambda function version\\. A snapshot is a cached state of your initialized function, including all of its dependencies\\. The function is initialized just once and the cached state is reused for all future invocations, improving application performance by reducing the number of times your function must be initialized\\. To learn more, see [Improving startup performance with Lambda SnapStart](https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html) in the *AWS Lambda Developer Guide*\\. \n*Type*: [SnapStart](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`SnapStart`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html) property of an `AWS::Lambda::Function` resource\\.",
61236128
"title": "SnapStart"
61246129
},
6130+
"SourceKMSKeyArn": {
6131+
"$ref": "#/definitions/PassThroughProp"
6132+
},
61256133
"Tags": {
61266134
"markdownDescription": "A map \\(string to string\\) that specifies the tags added to this function\\. For details about valid keys and values for tags, see [Tag Key and Value Requirements](https://docs.aws.amazon.com/lambda/latest/dg/configuration-tags.html#configuration-tags-restrictions) in the *AWS Lambda Developer Guide*\\. \nWhen the stack is created, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\. \n*Type*: Map \n*Required*: No \n*AWS CloudFormation compatibility*: This property is similar to the [`Tags`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-tags) property of an `AWS::Lambda::Function` resource\\. The `Tags` property in AWS SAM consists of key\\-value pairs \\(whereas in AWS CloudFormation this property consists of a list of `Tag` objects\\)\\. Also, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\.",
61276135
"title": "Tags",

0 commit comments

Comments
 (0)