Skip to content

Commit

Permalink
Release v1.26.0 (#1680) (#1685)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
6 people authored Aug 14, 2020
1 parent d09ed7b commit 02ec8bf
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 11 deletions.
10 changes: 10 additions & 0 deletions docs/cloudformation_compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ StartingPosition All
BatchSize All
======================== ================================== ========================

MSK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
======================== ================================== ========================
Property Name Intrinsic(s) Supported Reasons
======================== ================================== ========================
Stream All
Topics All
StartingPosition All
======================== ================================== ========================

DynamoDB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
======================== ================================== ========================
Expand Down
28 changes: 28 additions & 0 deletions docs/internals/generated_resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,34 @@ AWS::Lambda::Permission MyFunction\ **MyTrigger**\ Permission
AWS::Lambda::EventSourceMapping MyFunction\ **MyTrigger**
================================== ================================

MSK
^^^^^^^

Example:

.. code:: yaml
MyFunction:
Type: AWS::Serverless::Function
Properties:
...
Events:
MyTrigger:
Type: MSK
Properties:
Stream: arn:aws:kafka:us-east-1:123456789012:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2
StartingPosition: TRIM_HORIZON
...
Additional generated resources:

================================== ================================
CloudFormation Resource Type Logical ID
================================== ================================
AWS::Lambda::Permission MyFunction\ **MyTrigger**\ Permission
AWS::Lambda::EventSourceMapping MyFunction\ **MyTrigger**
================================== ================================

SQS
^^^

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.25.0"
__version__ = "1.26.0"
17 changes: 14 additions & 3 deletions samtranslator/model/eventsources/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class PullEventSource(ResourceMacro):
"""Base class for pull event sources for SAM Functions.
The pull events are Kinesis Streams, DynamoDB Streams, and SQS Queues. All of these correspond to an
The pull events are Kinesis Streams, DynamoDB Streams, Kafka Streams and SQS Queues. All of these correspond to an
EventSourceMapping in Lambda, and require that the execution role be given to Kinesis Streams, DynamoDB
Streams, or SQS Queues, respectively.
Expand All @@ -30,6 +30,7 @@ class PullEventSource(ResourceMacro):
"MaximumRecordAgeInSeconds": PropertyType(False, is_type(int)),
"DestinationConfig": PropertyType(False, is_type(dict)),
"ParallelizationFactor": PropertyType(False, is_type(int)),
"Topics": PropertyType(False, is_type(list)),
}

def get_policy_arn(self):
Expand Down Expand Up @@ -61,11 +62,11 @@ def to_cloudformation(self, **kwargs):

if not self.Stream and not self.Queue:
raise InvalidEventException(
self.relative_id, "No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided."
self.relative_id, "No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) provided."
)

if self.Stream and not self.StartingPosition:
raise InvalidEventException(self.relative_id, "StartingPosition is required for Kinesis and DynamoDB.")
raise InvalidEventException(self.relative_id, "StartingPosition is required for Kinesis, DynamoDB and MSK.")

lambda_eventsourcemapping.FunctionName = function_name_or_arn
lambda_eventsourcemapping.EventSourceArn = self.Stream or self.Queue
Expand All @@ -77,6 +78,7 @@ def to_cloudformation(self, **kwargs):
lambda_eventsourcemapping.BisectBatchOnFunctionError = self.BisectBatchOnFunctionError
lambda_eventsourcemapping.MaximumRecordAgeInSeconds = self.MaximumRecordAgeInSeconds
lambda_eventsourcemapping.ParallelizationFactor = self.ParallelizationFactor
lambda_eventsourcemapping.Topics = self.Topics

destination_config_policy = None
if self.DestinationConfig:
Expand Down Expand Up @@ -159,3 +161,12 @@ class SQS(PullEventSource):

def get_policy_arn(self):
return ArnGenerator.generate_aws_managed_policy_arn("service-role/AWSLambdaSQSQueueExecutionRole")


class MSK(PullEventSource):
"""MSK event source."""

resource_type = "MSK"

def get_policy_arn(self):
return ArnGenerator.generate_aws_managed_policy_arn("service-role/AWSLambdaMSKExecutionRole")
1 change: 1 addition & 0 deletions samtranslator/model/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class LambdaEventSourceMapping(Resource):
"DestinationConfig": PropertyType(False, is_type(dict)),
"ParallelizationFactor": PropertyType(False, is_type(int)),
"StartingPosition": PropertyType(False, is_str()),
"Topics": PropertyType(False, is_type(list)),
}

runtime_attrs = {"name": lambda self: ref(self.logical_id)}
Expand Down
24 changes: 24 additions & 0 deletions samtranslator/validator/sam_schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@
{
"$ref": "#/definitions/AWS::Serverless::Function.KinesisEvent"
},
{
"$ref": "#/definitions/AWS::Serverless::Function.MSKEvent"
},
{
"$ref": "#/definitions/AWS::Serverless::Function.SQSEvent"
},
Expand Down Expand Up @@ -586,6 +589,27 @@
],
"type": "object"
},
"AWS::Serverless::Function.MSKEvent": {
"additionalProperties": false,
"properties": {
"StartingPosition": {
"type": "string"
},
"Stream": {
"type": "string"
},
"Topics": {
"type": "array"
}
},
"required": [
"StartingPosition",
"Stream",
"Topics"
],
"type": "object"
},

"AWS::Serverless::Function.SQSEvent": {
"additionalProperties": false,
"properties": {
Expand Down
14 changes: 14 additions & 0 deletions tests/translator/input/streams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ Resources:
Stream: arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291
BatchSize: 200
StartingPosition: LATEST
MSKFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: s3://sam-demo-bucket/streams.zip
Handler: stream.msk_handler
Runtime: python2.7
Events:
MyMSKStream:
Type: MSK
Properties:
Stream: arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2
StartingPosition: LATEST
Topics:
- "Topic1"
61 changes: 61 additions & 0 deletions tests/translator/output/aws-cn/streams.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@
}]
}
},
"MSKFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "streams.zip"
},
"Handler": "stream.msk_handler",
"Role": {
"Fn::GetAtt": [
"MSKFunctionRole",
"Arn"
]
},
"Runtime": "python2.7",
"Tags": [{
"Value": "SAM",
"Key": "lambda:createdBy"
}]
}
},
"DynamoDBFunctionMyDDBStream": {
"Type": "AWS::Lambda::EventSourceMapping",
"Properties": {
Expand Down Expand Up @@ -122,6 +143,46 @@
}]
}
}
},
"MSKFunctionMyMSKStream": {
"Type": "AWS::Lambda::EventSourceMapping",
"Properties": {
"EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2",
"FunctionName": {
"Ref": "MSKFunction"
},
"StartingPosition": "LATEST",
"Topics": ["Topic1"]
}
},
"MSKFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}]
}
}
}
}
}
61 changes: 61 additions & 0 deletions tests/translator/output/aws-us-gov/streams.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@
}]
}
},
"MSKFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "streams.zip"
},
"Handler": "stream.msk_handler",
"Role": {
"Fn::GetAtt": [
"MSKFunctionRole",
"Arn"
]
},
"Runtime": "python2.7",
"Tags": [{
"Value": "SAM",
"Key": "lambda:createdBy"
}]
}
},
"DynamoDBFunctionMyDDBStream": {
"Type": "AWS::Lambda::EventSourceMapping",
"Properties": {
Expand Down Expand Up @@ -122,6 +143,46 @@
}]
}
}
},
"MSKFunctionMyMSKStream": {
"Type": "AWS::Lambda::EventSourceMapping",
"Properties": {
"EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2",
"FunctionName": {
"Ref": "MSKFunction"
},
"StartingPosition": "LATEST",
"Topics": ["Topic1"]
}
},
"MSKFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}]
}
}
}
}
}
4 changes: 2 additions & 2 deletions tests/translator/output/error_missing_queue.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"errors": [{
"errorMessage": "Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided."
"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."
}],
"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."
"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."
}
4 changes: 2 additions & 2 deletions tests/translator/output/error_missing_startingposition.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"errors": [{
"errorMessage": "Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis and DynamoDB."
"errorMessage": "Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis, DynamoDB and MSK."
}],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis and DynamoDB."
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis, DynamoDB and MSK."
}
4 changes: 2 additions & 2 deletions tests/translator/output/error_missing_stream.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"errors": [{
"errorMessage": "Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided."
"errorMessage": "Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) provided."
}],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided."
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) provided."
}
Loading

0 comments on commit 02ec8bf

Please sign in to comment.