Skip to content

Commit 02ec8bf

Browse files
sriram-mvSteve Brownjtaylor00jfussawood45
authored
Release v1.26.0 (#1680) (#1685)
* feat: add support for VPCEndpointIds in EndpointConfiguration * fix: update formatting with black * docs: update 2016-10-31.md * docs: added api endpointconfiguration example * docs: make example more generic * fix: remove nested EndpointConfiguration types from output * fix: only allow one EndpointConfiguration Type * doc: update example to reflect only allowing one EndpointConfiguration Type * fix : missing UserPool properties (#1506) (#1581) * fix: resource policy generation for {path+} (#1580) * refactor: Remove 2016-10-31 examples * update PR template * adjust pr template * Adding authorization scopes as list validation in ApiGatewayAuthorizer (v1 and v2). (#1670) * Adding authorization scopes as list validation in ApiGatewayAuthorizer and ApiGatewayV2Authorizer. * make black. * Adding functional test for invalid auth scope. * adding error condition for invalid test. * removing test template file. * feat: MSK event type support for AWS::Serverless::Function Co-authored-by: Steve Brown <[email protected]> Co-authored-by: jtaylor00 <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Alex Wood <[email protected]> Co-authored-by: Tarun <[email protected]> Co-authored-by: Steve Brown <[email protected]> Co-authored-by: jtaylor00 <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Alex Wood <[email protected]> Co-authored-by: Tarun <[email protected]>
1 parent d09ed7b commit 02ec8bf

File tree

14 files changed

+308
-11
lines changed

14 files changed

+308
-11
lines changed

docs/cloudformation_compatibility.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ StartingPosition All
108108
BatchSize All
109109
======================== ================================== ========================
110110

111+
MSK
112+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113+
======================== ================================== ========================
114+
Property Name Intrinsic(s) Supported Reasons
115+
======================== ================================== ========================
116+
Stream All
117+
Topics All
118+
StartingPosition All
119+
======================== ================================== ========================
120+
111121
DynamoDB
112122
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113123
======================== ================================== ========================

docs/internals/generated_resources.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,34 @@ AWS::Lambda::Permission MyFunction\ **MyTrigger**\ Permission
326326
AWS::Lambda::EventSourceMapping MyFunction\ **MyTrigger**
327327
================================== ================================
328328

329+
MSK
330+
^^^^^^^
331+
332+
Example:
333+
334+
.. code:: yaml
335+
336+
MyFunction:
337+
Type: AWS::Serverless::Function
338+
Properties:
339+
...
340+
Events:
341+
MyTrigger:
342+
Type: MSK
343+
Properties:
344+
Stream: arn:aws:kafka:us-east-1:123456789012:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2
345+
StartingPosition: TRIM_HORIZON
346+
...
347+
348+
Additional generated resources:
349+
350+
================================== ================================
351+
CloudFormation Resource Type Logical ID
352+
================================== ================================
353+
AWS::Lambda::Permission MyFunction\ **MyTrigger**\ Permission
354+
AWS::Lambda::EventSourceMapping MyFunction\ **MyTrigger**
355+
================================== ================================
356+
329357
SQS
330358
^^^
331359

samtranslator/__init__.py

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

samtranslator/model/eventsources/pull.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class PullEventSource(ResourceMacro):
1111
"""Base class for pull event sources for SAM Functions.
1212
13-
The pull events are Kinesis Streams, DynamoDB Streams, and SQS Queues. All of these correspond to an
13+
The pull events are Kinesis Streams, DynamoDB Streams, Kafka Streams and SQS Queues. All of these correspond to an
1414
EventSourceMapping in Lambda, and require that the execution role be given to Kinesis Streams, DynamoDB
1515
Streams, or SQS Queues, respectively.
1616
@@ -30,6 +30,7 @@ class PullEventSource(ResourceMacro):
3030
"MaximumRecordAgeInSeconds": PropertyType(False, is_type(int)),
3131
"DestinationConfig": PropertyType(False, is_type(dict)),
3232
"ParallelizationFactor": PropertyType(False, is_type(int)),
33+
"Topics": PropertyType(False, is_type(list)),
3334
}
3435

3536
def get_policy_arn(self):
@@ -61,11 +62,11 @@ def to_cloudformation(self, **kwargs):
6162

6263
if not self.Stream and not self.Queue:
6364
raise InvalidEventException(
64-
self.relative_id, "No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided."
65+
self.relative_id, "No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) provided."
6566
)
6667

6768
if self.Stream and not self.StartingPosition:
68-
raise InvalidEventException(self.relative_id, "StartingPosition is required for Kinesis and DynamoDB.")
69+
raise InvalidEventException(self.relative_id, "StartingPosition is required for Kinesis, DynamoDB and MSK.")
6970

7071
lambda_eventsourcemapping.FunctionName = function_name_or_arn
7172
lambda_eventsourcemapping.EventSourceArn = self.Stream or self.Queue
@@ -77,6 +78,7 @@ def to_cloudformation(self, **kwargs):
7778
lambda_eventsourcemapping.BisectBatchOnFunctionError = self.BisectBatchOnFunctionError
7879
lambda_eventsourcemapping.MaximumRecordAgeInSeconds = self.MaximumRecordAgeInSeconds
7980
lambda_eventsourcemapping.ParallelizationFactor = self.ParallelizationFactor
81+
lambda_eventsourcemapping.Topics = self.Topics
8082

8183
destination_config_policy = None
8284
if self.DestinationConfig:
@@ -159,3 +161,12 @@ class SQS(PullEventSource):
159161

160162
def get_policy_arn(self):
161163
return ArnGenerator.generate_aws_managed_policy_arn("service-role/AWSLambdaSQSQueueExecutionRole")
164+
165+
166+
class MSK(PullEventSource):
167+
"""MSK event source."""
168+
169+
resource_type = "MSK"
170+
171+
def get_policy_arn(self):
172+
return ArnGenerator.generate_aws_managed_policy_arn("service-role/AWSLambdaMSKExecutionRole")

samtranslator/model/lambda_.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class LambdaEventSourceMapping(Resource):
6969
"DestinationConfig": PropertyType(False, is_type(dict)),
7070
"ParallelizationFactor": PropertyType(False, is_type(int)),
7171
"StartingPosition": PropertyType(False, is_str()),
72+
"Topics": PropertyType(False, is_type(list)),
7273
}
7374

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

samtranslator/validator/sam_schema/schema.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,9 @@
474474
{
475475
"$ref": "#/definitions/AWS::Serverless::Function.KinesisEvent"
476476
},
477+
{
478+
"$ref": "#/definitions/AWS::Serverless::Function.MSKEvent"
479+
},
477480
{
478481
"$ref": "#/definitions/AWS::Serverless::Function.SQSEvent"
479482
},
@@ -586,6 +589,27 @@
586589
],
587590
"type": "object"
588591
},
592+
"AWS::Serverless::Function.MSKEvent": {
593+
"additionalProperties": false,
594+
"properties": {
595+
"StartingPosition": {
596+
"type": "string"
597+
},
598+
"Stream": {
599+
"type": "string"
600+
},
601+
"Topics": {
602+
"type": "array"
603+
}
604+
},
605+
"required": [
606+
"StartingPosition",
607+
"Stream",
608+
"Topics"
609+
],
610+
"type": "object"
611+
},
612+
589613
"AWS::Serverless::Function.SQSEvent": {
590614
"additionalProperties": false,
591615
"properties": {

tests/translator/input/streams.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ Resources:
2626
Stream: arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291
2727
BatchSize: 200
2828
StartingPosition: LATEST
29+
MSKFunction:
30+
Type: 'AWS::Serverless::Function'
31+
Properties:
32+
CodeUri: s3://sam-demo-bucket/streams.zip
33+
Handler: stream.msk_handler
34+
Runtime: python2.7
35+
Events:
36+
MyMSKStream:
37+
Type: MSK
38+
Properties:
39+
Stream: arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2
40+
StartingPosition: LATEST
41+
Topics:
42+
- "Topic1"

tests/translator/output/aws-cn/streams.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@
4242
}]
4343
}
4444
},
45+
"MSKFunction": {
46+
"Type": "AWS::Lambda::Function",
47+
"Properties": {
48+
"Code": {
49+
"S3Bucket": "sam-demo-bucket",
50+
"S3Key": "streams.zip"
51+
},
52+
"Handler": "stream.msk_handler",
53+
"Role": {
54+
"Fn::GetAtt": [
55+
"MSKFunctionRole",
56+
"Arn"
57+
]
58+
},
59+
"Runtime": "python2.7",
60+
"Tags": [{
61+
"Value": "SAM",
62+
"Key": "lambda:createdBy"
63+
}]
64+
}
65+
},
4566
"DynamoDBFunctionMyDDBStream": {
4667
"Type": "AWS::Lambda::EventSourceMapping",
4768
"Properties": {
@@ -122,6 +143,46 @@
122143
}]
123144
}
124145
}
146+
},
147+
"MSKFunctionMyMSKStream": {
148+
"Type": "AWS::Lambda::EventSourceMapping",
149+
"Properties": {
150+
"EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2",
151+
"FunctionName": {
152+
"Ref": "MSKFunction"
153+
},
154+
"StartingPosition": "LATEST",
155+
"Topics": ["Topic1"]
156+
}
157+
},
158+
"MSKFunctionRole": {
159+
"Type": "AWS::IAM::Role",
160+
"Properties": {
161+
"ManagedPolicyArns": [
162+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
163+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole"
164+
],
165+
"Tags": [
166+
{
167+
"Value": "SAM",
168+
"Key": "lambda:createdBy"
169+
}
170+
],
171+
"AssumeRolePolicyDocument": {
172+
"Version": "2012-10-17",
173+
"Statement": [{
174+
"Action": [
175+
"sts:AssumeRole"
176+
],
177+
"Effect": "Allow",
178+
"Principal": {
179+
"Service": [
180+
"lambda.amazonaws.com"
181+
]
182+
}
183+
}]
184+
}
185+
}
125186
}
126187
}
127188
}

tests/translator/output/aws-us-gov/streams.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@
4242
}]
4343
}
4444
},
45+
"MSKFunction": {
46+
"Type": "AWS::Lambda::Function",
47+
"Properties": {
48+
"Code": {
49+
"S3Bucket": "sam-demo-bucket",
50+
"S3Key": "streams.zip"
51+
},
52+
"Handler": "stream.msk_handler",
53+
"Role": {
54+
"Fn::GetAtt": [
55+
"MSKFunctionRole",
56+
"Arn"
57+
]
58+
},
59+
"Runtime": "python2.7",
60+
"Tags": [{
61+
"Value": "SAM",
62+
"Key": "lambda:createdBy"
63+
}]
64+
}
65+
},
4566
"DynamoDBFunctionMyDDBStream": {
4667
"Type": "AWS::Lambda::EventSourceMapping",
4768
"Properties": {
@@ -122,6 +143,46 @@
122143
}]
123144
}
124145
}
146+
},
147+
"MSKFunctionMyMSKStream": {
148+
"Type": "AWS::Lambda::EventSourceMapping",
149+
"Properties": {
150+
"EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2",
151+
"FunctionName": {
152+
"Ref": "MSKFunction"
153+
},
154+
"StartingPosition": "LATEST",
155+
"Topics": ["Topic1"]
156+
}
157+
},
158+
"MSKFunctionRole": {
159+
"Type": "AWS::IAM::Role",
160+
"Properties": {
161+
"ManagedPolicyArns": [
162+
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
163+
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole"
164+
],
165+
"Tags": [
166+
{
167+
"Value": "SAM",
168+
"Key": "lambda:createdBy"
169+
}
170+
],
171+
"AssumeRolePolicyDocument": {
172+
"Version": "2012-10-17",
173+
"Statement": [{
174+
"Action": [
175+
"sts:AssumeRole"
176+
],
177+
"Effect": "Allow",
178+
"Principal": {
179+
"Service": [
180+
"lambda.amazonaws.com"
181+
]
182+
}
183+
}]
184+
}
185+
}
125186
}
126187
}
127188
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"errors": [{
3-
"errorMessage": "Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided."
3+
"errorMessage": "Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) provided."
44
}],
5-
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided."
5+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) provided."
66
}

0 commit comments

Comments
 (0)