Skip to content

Commit bd88284

Browse files
authored
Merge branch 'main' into release-v1.94.0
2 parents caafeec + 564d7ad commit bd88284

25 files changed

+2049
-30
lines changed

.cfnlintrc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,15 @@ 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
137138
- tests/translator/output/**/function_with_snapstart.json # Snapstart intentionally not attached to a lambda version which causes lint issues
138139
- tests/translator/output/**/managed_policies_everything.json # intentionally contains wrong arns
139140
- tests/translator/output/**/function_with_provisioned_poller_config.json
141+
- tests/translator/output/**/function_with_metrics_config.json
142+
140143
ignore_checks:
141144
- E2531 # Deprecated runtime; not relevant for transform tests
142145
- E2533 # Another deprecated runtime; not relevant for transform tests

samtranslator/internal/schema_source/aws_serverless_function.py

Lines changed: 8 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):
@@ -178,6 +178,7 @@ class KinesisEventProperties(BaseModel):
178178
StartingPositionTimestamp: Optional[PassThroughProp] = kinesiseventproperties("StartingPositionTimestamp")
179179
Stream: PassThroughProp = kinesiseventproperties("Stream")
180180
TumblingWindowInSeconds: Optional[PassThroughProp] = kinesiseventproperties("TumblingWindowInSeconds")
181+
MetricsConfig: Optional[PassThroughProp]
181182

182183

183184
class KinesisEvent(BaseModel):
@@ -203,6 +204,7 @@ class DynamoDBEventProperties(BaseModel):
203204
StartingPositionTimestamp: Optional[PassThroughProp] = dynamodbeventproperties("StartingPositionTimestamp")
204205
Stream: PassThroughProp = dynamodbeventproperties("Stream")
205206
TumblingWindowInSeconds: Optional[PassThroughProp] = dynamodbeventproperties("TumblingWindowInSeconds")
207+
MetricsConfig: Optional[PassThroughProp]
206208

207209

208210
class DynamoDBEvent(BaseModel):
@@ -241,6 +243,7 @@ class SQSEventProperties(BaseModel):
241243
MaximumBatchingWindowInSeconds: Optional[PassThroughProp] = sqseventproperties("MaximumBatchingWindowInSeconds")
242244
Queue: PassThroughProp = sqseventproperties("Queue")
243245
ScalingConfig: Optional[PassThroughProp] # Update docs when live
246+
MetricsConfig: Optional[PassThroughProp]
244247

245248

246249
class SQSEvent(BaseModel):
@@ -515,6 +518,7 @@ class ScheduleV2Event(BaseModel):
515518
RuntimeManagementConfig = Optional[PassThroughProp] # TODO: check the type
516519
LoggingConfig = Optional[PassThroughProp] # TODO: add documentation
517520
RecursiveLoop = Optional[PassThroughProp]
521+
SourceKMSKeyArn = Optional[PassThroughProp]
518522

519523

520524
class Properties(BaseModel):
@@ -642,6 +646,7 @@ class Properties(BaseModel):
642646
VpcConfig: Optional[VpcConfig] = prop("VpcConfig")
643647
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
644648
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
649+
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
645650

646651

647652
class Globals(BaseModel):
@@ -701,6 +706,7 @@ class Globals(BaseModel):
701706
RuntimeManagementConfig: Optional[RuntimeManagementConfig] = prop("RuntimeManagementConfig")
702707
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
703708
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
709+
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
704710

705711

706712
class Resource(ResourceAttributes):

samtranslator/model/eventsources/pull.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class PullEventSource(ResourceMacro, metaclass=ABCMeta):
5656
"ConsumerGroupId": PropertyType(False, IS_STR),
5757
"ScalingConfig": PropertyType(False, IS_DICT),
5858
"ProvisionedPollerConfig": PropertyType(False, IS_DICT),
59+
"MetricsConfig": PropertyType(False, IS_DICT),
5960
}
6061

6162
BatchSize: Optional[Intrinsicable[int]]
@@ -80,6 +81,7 @@ class PullEventSource(ResourceMacro, metaclass=ABCMeta):
8081
ConsumerGroupId: Optional[Intrinsicable[str]]
8182
ScalingConfig: Optional[Dict[str, Any]]
8283
ProvisionedPollerConfig: Optional[Dict[str, Any]]
84+
MetricsConfig: Optional[Dict[str, Any]]
8385

8486
@abstractmethod
8587
def get_policy_arn(self) -> Optional[str]:
@@ -148,6 +150,7 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: P
148150
lambda_eventsourcemapping.KmsKeyArn = self.KmsKeyArn
149151
lambda_eventsourcemapping.ScalingConfig = self.ScalingConfig
150152
lambda_eventsourcemapping.ProvisionedPollerConfig = self.ProvisionedPollerConfig
153+
lambda_eventsourcemapping.MetricsConfig = self.MetricsConfig
151154
self._validate_filter_criteria()
152155

153156
if self.KafkaBootstrapServers:

samtranslator/model/lambda_.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class LambdaEventSourceMapping(Resource):
123123
"SelfManagedKafkaEventSourceConfig": GeneratedProperty(),
124124
"ScalingConfig": GeneratedProperty(),
125125
"ProvisionedPollerConfig": GeneratedProperty(),
126+
"MetricsConfig": GeneratedProperty(),
126127
}
127128

128129
runtime_attrs = {"name": lambda self: ref(self.logical_id)}

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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274755,6 +274755,9 @@
274755274755
"markdownDescription": "The maximum number of times to retry when the function returns an error\\. \n*Type*: Integer \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`MaximumRetryAttempts`](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumretryattempts) property of an `AWS::Lambda::EventSourceMapping` resource\\.",
274756274756
"title": "MaximumRetryAttempts"
274757274757
},
274758+
"MetricsConfig": {
274759+
"$ref": "#/definitions/PassThroughProp"
274760+
},
274758274761
"ParallelizationFactor": {
274759274762
"allOf": [
274760274763
{
@@ -274990,7 +274993,8 @@
274990274993
"SQS",
274991274994
"SNS",
274992274995
"Lambda",
274993-
"EventBridge"
274996+
"EventBridge",
274997+
"S3Bucket"
274994274998
],
274995274999
"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\\.",
274996275000
"title": "Type",
@@ -275020,7 +275024,8 @@
275020275024
"SQS",
275021275025
"SNS",
275022275026
"Lambda",
275023-
"EventBridge"
275027+
"EventBridge",
275028+
"S3Bucket"
275024275029
],
275025275030
"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\\.",
275026275031
"title": "Type",
@@ -275502,6 +275507,9 @@
275502275507
"markdownDescription": "The maximum number of times to retry when the function returns an error\\. \n*Type*: Integer \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`MaximumRetryAttempts`](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumretryattempts) property of an `AWS::Lambda::EventSourceMapping` resource\\.",
275503275508
"title": "MaximumRetryAttempts"
275504275509
},
275510+
"MetricsConfig": {
275511+
"$ref": "#/definitions/PassThroughProp"
275512+
},
275505275513
"ParallelizationFactor": {
275506275514
"allOf": [
275507275515
{
@@ -276778,6 +276786,9 @@
276778276786
"markdownDescription": "The maximum amount of time, in seconds, to gather records before invoking the function\\. \n*Type*: Integer \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`MaximumBatchingWindowInSeconds`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds) property of an `AWS::Lambda::EventSourceMapping` resource\\.",
276779276787
"title": "MaximumBatchingWindowInSeconds"
276780276788
},
276789+
"MetricsConfig": {
276790+
"$ref": "#/definitions/PassThroughProp"
276791+
},
276781276792
"Queue": {
276782276793
"allOf": [
276783276794
{
@@ -278791,6 +278802,9 @@
278791278802
"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\\.",
278792278803
"title": "SnapStart"
278793278804
},
278805+
"SourceKMSKeyArn": {
278806+
"$ref": "#/definitions/PassThroughProp"
278807+
},
278794278808
"Tags": {
278795278809
"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\\.",
278796278810
"title": "Tags",
@@ -279185,6 +279199,9 @@
279185279199
"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\\.",
279186279200
"title": "SnapStart"
279187279201
},
279202+
"SourceKMSKeyArn": {
279203+
"$ref": "#/definitions/PassThroughProp"
279204+
},
279188279205
"Tags": {
279189279206
"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\\.",
279190279207
"title": "Tags",

0 commit comments

Comments
 (0)