Skip to content

Commit 0cc9f7e

Browse files
authored
Merge pull request #3689 from aws/tmp/1732213576/main
Merge main to develop
2 parents f2da50c + e4acbcf commit 0cc9f7e

17 files changed

+1618
-11
lines changed

.cfnlintrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ ignore_templates:
137137
- tests/translator/output/**/function_with_intrinsics_resource_attribute.json # CFN now supports intrinsics in DeletionPolicy
138138
- tests/translator/output/**/function_with_snapstart.json # Snapstart intentionally not attached to a lambda version which causes lint issues
139139
- tests/translator/output/**/managed_policies_everything.json # intentionally contains wrong arns
140+
- tests/translator/output/**/function_with_metrics_config.json
140141
ignore_checks:
141142
- E2531 # Deprecated runtime; not relevant for transform tests
142143
- E2533 # Another deprecated runtime; not relevant for transform tests

samtranslator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.92.0"
1+
__version__ = "1.93.0"

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):
@@ -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):

samtranslator/model/eventsources/pull.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class PullEventSource(ResourceMacro, metaclass=ABCMeta):
5555
"KmsKeyArn": PassThroughProperty(False),
5656
"ConsumerGroupId": PropertyType(False, IS_STR),
5757
"ScalingConfig": PropertyType(False, IS_DICT),
58+
"MetricsConfig": PropertyType(False, IS_DICT),
5859
}
5960

6061
BatchSize: Optional[Intrinsicable[int]]
@@ -78,6 +79,7 @@ class PullEventSource(ResourceMacro, metaclass=ABCMeta):
7879
KmsKeyArn: Optional[Intrinsicable[str]]
7980
ConsumerGroupId: Optional[Intrinsicable[str]]
8081
ScalingConfig: Optional[Dict[str, Any]]
82+
MetricsConfig: Optional[Dict[str, Any]]
8183

8284
@abstractmethod
8385
def get_policy_arn(self) -> Optional[str]:
@@ -145,6 +147,7 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: P
145147
lambda_eventsourcemapping.FilterCriteria = self.FilterCriteria
146148
lambda_eventsourcemapping.KmsKeyArn = self.KmsKeyArn
147149
lambda_eventsourcemapping.ScalingConfig = self.ScalingConfig
150+
lambda_eventsourcemapping.MetricsConfig = self.MetricsConfig
148151
self._validate_filter_criteria()
149152

150153
if self.KafkaBootstrapServers:

samtranslator/model/lambda_.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class LambdaEventSourceMapping(Resource):
122122
"AmazonManagedKafkaEventSourceConfig": GeneratedProperty(),
123123
"SelfManagedKafkaEventSourceConfig": GeneratedProperty(),
124124
"ScalingConfig": GeneratedProperty(),
125+
"MetricsConfig": GeneratedProperty(),
125126
}
126127

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

samtranslator/model/sam_resources.py

Lines changed: 4 additions & 2 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
@@ -441,7 +441,7 @@ def _validate_and_inject_resource(
441441
ARN property, so to handle conditional ifs we have to inject if conditions in the auto created
442442
SQS/SNS resources as well as in the policy documents.
443443
"""
444-
accepted_types_list = ["SQS", "SNS", "EventBridge", "Lambda"]
444+
accepted_types_list = ["SQS", "SNS", "EventBridge", "Lambda", "S3Bucket"]
445445
auto_inject_list = ["SQS", "SNS"]
446446
resource: Optional[Union[SNSTopic, SQSQueue]] = None
447447
policy = {}
@@ -632,6 +632,8 @@ def _add_event_invoke_managed_policy(
632632
return IAMRolePolicies.event_bus_put_events_role_policy(dest_arn, logical_id)
633633
if _type == "Lambda":
634634
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)
635637
return {}
636638

637639
def _construct_role(

samtranslator/schema/schema.json

Lines changed: 13 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
{
@@ -276759,6 +276767,9 @@
276759276767
"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\\.",
276760276768
"title": "MaximumBatchingWindowInSeconds"
276761276769
},
276770+
"MetricsConfig": {
276771+
"$ref": "#/definitions/PassThroughProp"
276772+
},
276762276773
"Queue": {
276763276774
"allOf": [
276764276775
{

schema_source/sam.schema.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,9 @@
10041004
"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\\.",
10051005
"title": "MaximumRetryAttempts"
10061006
},
1007+
"MetricsConfig": {
1008+
"$ref": "#/definitions/PassThroughProp"
1009+
},
10071010
"ParallelizationFactor": {
10081011
"allOf": [
10091012
{
@@ -1257,7 +1260,8 @@
12571260
"SQS",
12581261
"SNS",
12591262
"Lambda",
1260-
"EventBridge"
1263+
"EventBridge",
1264+
"S3Bucket"
12611265
],
12621266
"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\\.",
12631267
"title": "Type",
@@ -1287,7 +1291,8 @@
12871291
"SQS",
12881292
"SNS",
12891293
"Lambda",
1290-
"EventBridge"
1294+
"EventBridge",
1295+
"S3Bucket"
12911296
],
12921297
"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\\.",
12931298
"title": "Type",
@@ -1769,6 +1774,9 @@
17691774
"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\\.",
17701775
"title": "MaximumRetryAttempts"
17711776
},
1777+
"MetricsConfig": {
1778+
"$ref": "#/definitions/PassThroughProp"
1779+
},
17721780
"ParallelizationFactor": {
17731781
"allOf": [
17741782
{
@@ -2957,6 +2965,9 @@
29572965
"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\\.",
29582966
"title": "MaximumBatchingWindowInSeconds"
29592967
},
2968+
"MetricsConfig": {
2969+
"$ref": "#/definitions/PassThroughProp"
2970+
},
29602971
"Queue": {
29612972
"allOf": [
29622973
{
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
Parameters:
2+
S3BucketArn1:
3+
Type: String
4+
Default: arn:aws:s3::123456789012:my_bucket-1
5+
S3BucketArn2:
6+
Type: String
7+
Default: arn:aws:s3::123456789012:my_bucket-2
8+
Globals:
9+
Function:
10+
AutoPublishAlias: live
11+
EventInvokeConfig:
12+
MaximumEventAgeInSeconds: 70
13+
MaximumRetryAttempts: 1
14+
DestinationConfig:
15+
OnSuccess:
16+
Type: S3Bucket
17+
Destination: !Ref S3BucketArn1
18+
OnFailure:
19+
Type: S3Bucket
20+
Destination: !Ref S3BucketArn2
21+
22+
Resources:
23+
MyTestFunction:
24+
Type: AWS::Serverless::Function
25+
Properties:
26+
InlineCode: |
27+
exports.handler = function(event, context, callback) {
28+
var event_received_at = new Date().toISOString();
29+
console.log('Event received at: ' + event_received_at);
30+
console.log('Received event:', JSON.stringify(event, null, 2));
31+
32+
if (event.Success) {
33+
console.log("Success");
34+
context.callbackWaitsForEmptyEventLoop = false;
35+
callback(null);
36+
} else {
37+
console.log("Failure");
38+
context.callbackWaitsForEmptyEventLoop = false;
39+
callback(new Error("Failure from event, Success = false, I am failing!"), 'Destination Function Error Thrown');
40+
}
41+
};
42+
Handler: index.handler
43+
Runtime: nodejs12.x
44+
MemorySize: 1024
45+
46+
MyTestFunction2:
47+
Type: AWS::Serverless::Function
48+
Properties:
49+
EventInvokeConfig:
50+
MaximumEventAgeInSeconds: 70
51+
MaximumRetryAttempts: 1
52+
DestinationConfig:
53+
OnSuccess:
54+
Type: S3Bucket
55+
Destination: arn:aws:s3::123456789012:my_bucket-3
56+
OnFailure:
57+
Type: S3Bucket
58+
Destination: arn:aws:s3::123456789012:my_bucket-4
59+
InlineCode: |
60+
exports.handler = function(event, context, callback) {
61+
var event_received_at = new Date().toISOString();
62+
console.log('Event received at: ' + event_received_at);
63+
console.log('Received event:', JSON.stringify(event, null, 2));
64+
65+
if (event.Success) {
66+
console.log("Success");
67+
context.callbackWaitsForEmptyEventLoop = false;
68+
callback(null);
69+
} else {
70+
console.log("Failure");
71+
context.callbackWaitsForEmptyEventLoop = false;
72+
callback(new Error("Failure from event, Success = false, I am failing!"), 'Destination Function Error Thrown');
73+
}
74+
};
75+
Handler: index.handler
76+
Runtime: nodejs12.x
77+
MemorySize: 1024
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Resources:
2+
FilteredEventsFunction:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/metricsConfig.zip
6+
Handler: index.handler
7+
Runtime: nodejs16.x
8+
Events:
9+
KinesisStream:
10+
Type: Kinesis
11+
Properties:
12+
Stream: !GetAtt KinesisStream.Arn
13+
StartingPosition: LATEST
14+
MetricsConfig:
15+
Metrics:
16+
- EventCount
17+
FilterCriteria:
18+
Filters:
19+
- Pattern: '{"name": "value"}'
20+
- Pattern: '{"name2": "value2"}'
21+
DynamoDBStreamEvent:
22+
Type: DynamoDB
23+
Properties:
24+
Stream: !GetAtt DynamoDBTable.StreamArn
25+
StartingPosition: TRIM_HORIZON
26+
MetricsConfig:
27+
Metrics: []
28+
FilterCriteria:
29+
Filters: []
30+
MySqsQueue:
31+
Type: SQS
32+
Properties:
33+
Queue: !GetAtt MySqsQueue.Arn
34+
MetricsConfig:
35+
Metrics:
36+
- EventCount
37+
FilterCriteria:
38+
Filters:
39+
- Pattern: '{"name": "value"}'
40+
41+
KinesisStream:
42+
Type: AWS::Kinesis::Stream
43+
Properties:
44+
ShardCount: 1
45+
46+
DynamoDBTable:
47+
Type: AWS::DynamoDB::Table
48+
Properties:
49+
AttributeDefinitions:
50+
- AttributeName: id
51+
AttributeType: S
52+
BillingMode: PAY_PER_REQUEST
53+
KeySchema:
54+
- AttributeName: id
55+
KeyType: HASH
56+
57+
MySqsQueue:
58+
Type: AWS::SQS::Queue

0 commit comments

Comments
 (0)