From ed8852fd3e990279a7d7a6671824ff52498dd87f Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Thu, 12 Jan 2023 17:24:39 +0000 Subject: [PATCH 1/2] feat: Support SQS Maximum Concurrency --- samtranslator/model/eventsources/pull.py | 3 + samtranslator/model/lambda_.py | 1 + .../schema/aws_serverless_function.py | 1 + samtranslator/schema/schema.json | 3 + .../input/sqs_with_scaling_config.yaml | 16 +++++ .../aws-cn/sqs_with_scaling_config.json | 72 +++++++++++++++++++ .../aws-us-gov/sqs_with_scaling_config.json | 72 +++++++++++++++++++ .../output/sqs_with_scaling_config.json | 72 +++++++++++++++++++ 8 files changed, 240 insertions(+) create mode 100644 tests/translator/input/sqs_with_scaling_config.yaml create mode 100644 tests/translator/output/aws-cn/sqs_with_scaling_config.json create mode 100644 tests/translator/output/aws-us-gov/sqs_with_scaling_config.json create mode 100644 tests/translator/output/sqs_with_scaling_config.json diff --git a/samtranslator/model/eventsources/pull.py b/samtranslator/model/eventsources/pull.py index cd4fcbce9..d2484b54d 100644 --- a/samtranslator/model/eventsources/pull.py +++ b/samtranslator/model/eventsources/pull.py @@ -55,6 +55,7 @@ class PullEventSource(ResourceMacro): "KafkaBootstrapServers": PropertyType(False, is_type(list)), "FilterCriteria": PropertyType(False, is_type(dict)), "ConsumerGroupId": PropertyType(False, is_str()), + "ScalingConfig": PropertyType(False, is_type(dict)), } Stream: Optional[Intrinsicable[str]] @@ -78,6 +79,7 @@ class PullEventSource(ResourceMacro): KafkaBootstrapServers: Optional[List[Any]] FilterCriteria: Optional[Dict[str, Any]] ConsumerGroupId: Optional[Intrinsicable[str]] + ScalingConfig: Optional[Dict[str, Any]] def get_policy_arn(self): # type: ignore[no-untyped-def] raise NotImplementedError("Subclass must implement this method") @@ -137,6 +139,7 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] lambda_eventsourcemapping.TumblingWindowInSeconds = self.TumblingWindowInSeconds lambda_eventsourcemapping.FunctionResponseTypes = self.FunctionResponseTypes lambda_eventsourcemapping.FilterCriteria = self.FilterCriteria + lambda_eventsourcemapping.ScalingConfig = self.ScalingConfig self._validate_filter_criteria() # type: ignore[no-untyped-call] if self.KafkaBootstrapServers: diff --git a/samtranslator/model/lambda_.py b/samtranslator/model/lambda_.py index 763148bfe..c10331398 100644 --- a/samtranslator/model/lambda_.py +++ b/samtranslator/model/lambda_.py @@ -84,6 +84,7 @@ class LambdaEventSourceMapping(Resource): "FilterCriteria": PropertyType(False, is_type(dict)), "AmazonManagedKafkaEventSourceConfig": PropertyType(False, is_type(dict)), "SelfManagedKafkaEventSourceConfig": PropertyType(False, is_type(dict)), + "ScalingConfig": PropertyType(False, is_type(dict)), } runtime_attrs = {"name": lambda self: ref(self.logical_id)} diff --git a/samtranslator/schema/aws_serverless_function.py b/samtranslator/schema/aws_serverless_function.py index b00a86c84..768ce6b26 100644 --- a/samtranslator/schema/aws_serverless_function.py +++ b/samtranslator/schema/aws_serverless_function.py @@ -193,6 +193,7 @@ class SQSEventProperties(BaseModel): FilterCriteria: Optional[PassThrough] = sqseventproperties("FilterCriteria") MaximumBatchingWindowInSeconds: Optional[PassThrough] = sqseventproperties("MaximumBatchingWindowInSeconds") Queue: PassThrough = sqseventproperties("Queue") + ScalingConfig: Optional[PassThrough] # Update docs when live class SQSEvent(BaseModel): diff --git a/samtranslator/schema/schema.json b/samtranslator/schema/schema.json index b89de0ad2..96fa4c092 100644 --- a/samtranslator/schema/schema.json +++ b/samtranslator/schema/schema.json @@ -2291,6 +2291,9 @@ "title": "Queue", "description": "The ARN of the queue\\. \n*Type*: String \n*Required*: Yes \n*AWS CloudFormation compatibility*: This property is passed directly to the [`EventSourceArn`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn) property of an `AWS::Lambda::EventSourceMapping` resource\\.", "markdownDescription": "The ARN of the queue\\. \n*Type*: String \n*Required*: Yes \n*AWS CloudFormation compatibility*: This property is passed directly to the [`EventSourceArn`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn) property of an `AWS::Lambda::EventSourceMapping` resource\\." + }, + "ScalingConfig": { + "title": "Scalingconfig" } }, "additionalProperties": false diff --git a/tests/translator/input/sqs_with_scaling_config.yaml b/tests/translator/input/sqs_with_scaling_config.yaml new file mode 100644 index 000000000..1f52b013d --- /dev/null +++ b/tests/translator/input/sqs_with_scaling_config.yaml @@ -0,0 +1,16 @@ +Resources: + SQSFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/queues.zip + Handler: queue.sqs_handler + Runtime: python2.7 + Events: + MySqsQueue: + Type: SQS + Properties: + Queue: arn:aws:sqs:us-west-2:012345678901:my-queue + BatchSize: 10 + Enabled: false + ScalingConfig: + MaximumConcurrency: 500 diff --git a/tests/translator/output/aws-cn/sqs_with_scaling_config.json b/tests/translator/output/aws-cn/sqs_with_scaling_config.json new file mode 100644 index 000000000..39b604fec --- /dev/null +++ b/tests/translator/output/aws-cn/sqs_with_scaling_config.json @@ -0,0 +1,72 @@ +{ + "Resources": { + "SQSFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "queues.zip" + }, + "Handler": "queue.sqs_handler", + "Role": { + "Fn::GetAtt": [ + "SQSFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "SQSFunctionMySqsQueue": { + "Properties": { + "BatchSize": 10, + "Enabled": false, + "EventSourceArn": "arn:aws:sqs:us-west-2:012345678901:my-queue", + "FunctionName": { + "Ref": "SQSFunction" + }, + "ScalingConfig": { + "MaximumConcurrency": 500 + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SQSFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/aws-us-gov/sqs_with_scaling_config.json b/tests/translator/output/aws-us-gov/sqs_with_scaling_config.json new file mode 100644 index 000000000..2058620d9 --- /dev/null +++ b/tests/translator/output/aws-us-gov/sqs_with_scaling_config.json @@ -0,0 +1,72 @@ +{ + "Resources": { + "SQSFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "queues.zip" + }, + "Handler": "queue.sqs_handler", + "Role": { + "Fn::GetAtt": [ + "SQSFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "SQSFunctionMySqsQueue": { + "Properties": { + "BatchSize": 10, + "Enabled": false, + "EventSourceArn": "arn:aws:sqs:us-west-2:012345678901:my-queue", + "FunctionName": { + "Ref": "SQSFunction" + }, + "ScalingConfig": { + "MaximumConcurrency": 500 + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SQSFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/sqs_with_scaling_config.json b/tests/translator/output/sqs_with_scaling_config.json new file mode 100644 index 000000000..12e4d2ca2 --- /dev/null +++ b/tests/translator/output/sqs_with_scaling_config.json @@ -0,0 +1,72 @@ +{ + "Resources": { + "SQSFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "queues.zip" + }, + "Handler": "queue.sqs_handler", + "Role": { + "Fn::GetAtt": [ + "SQSFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "SQSFunctionMySqsQueue": { + "Properties": { + "BatchSize": 10, + "Enabled": false, + "EventSourceArn": "arn:aws:sqs:us-west-2:012345678901:my-queue", + "FunctionName": { + "Ref": "SQSFunction" + }, + "ScalingConfig": { + "MaximumConcurrency": 500 + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SQSFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} From 544d8a9fd2e4a32c13071fcd4f48347a19d594f4 Mon Sep 17 00:00:00 2001 From: aws-sam-cli-bot <46753707+aws-sam-cli-bot@users.noreply.github.com> Date: Thu, 12 Jan 2023 17:24:39 +0000 Subject: [PATCH 2/2] chore: bump version to 1.57.0 --- samtranslator/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samtranslator/__init__.py b/samtranslator/__init__.py index 4e9b170d0..d2259de9b 100644 --- a/samtranslator/__init__.py +++ b/samtranslator/__init__.py @@ -1 +1 @@ -__version__ = "1.55.0" +__version__ = "1.57.0"