Skip to content

Commit

Permalink
Merge branch 'main' into release-v1.94.0
Browse files Browse the repository at this point in the history
  • Loading branch information
godwingrs22 authored Nov 21, 2024
2 parents caafeec + 564d7ad commit bd88284
Show file tree
Hide file tree
Showing 25 changed files with 2,049 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .cfnlintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ ignore_templates:
- 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]
- 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]
- tests/translator/output/**/function_with_recursive_loop.json # Invalid Property Resources/RecursiveLoopParameterFunction/Properties/RecursiveLoop
- tests/translator/output/**/function_with_sourcekmskeyarn.json # Invalid Property Resources/SourceKMSKeyArnParameterFunction/Properties/SourceKMSKeyArn
- tests/translator/output/**/function_with_tracing.json # Obsolete DependsOn on resource
- tests/translator/output/**/api_with_propagate_tags.json # TODO: Intentional error transform tests. Will be updated.
- tests/translator/output/**/function_with_intrinsics_resource_attribute.json # CFN now supports intrinsics in DeletionPolicy
- tests/translator/output/**/function_with_snapstart.json # Snapstart intentionally not attached to a lambda version which causes lint issues
- tests/translator/output/**/managed_policies_everything.json # intentionally contains wrong arns
- tests/translator/output/**/function_with_provisioned_poller_config.json
- tests/translator/output/**/function_with_metrics_config.json

ignore_checks:
- E2531 # Deprecated runtime; not relevant for transform tests
- E2533 # Another deprecated runtime; not relevant for transform tests
Expand Down
10 changes: 8 additions & 2 deletions samtranslator/internal/schema_source/aws_serverless_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class DeadLetterQueue(BaseModel):

class EventInvokeOnFailure(BaseModel):
Destination: Optional[SamIntrinsicable[str]] = eventinvokeonfailure("Destination")
Type: Optional[Literal["SQS", "SNS", "Lambda", "EventBridge"]] = eventinvokeonfailure("Type")
Type: Optional[Literal["SQS", "SNS", "Lambda", "EventBridge", "S3Bucket"]] = eventinvokeonfailure("Type")


class EventInvokeOnSuccess(BaseModel):
Destination: Optional[SamIntrinsicable[str]] = eventinvokeonsuccess("Destination")
Type: Optional[Literal["SQS", "SNS", "Lambda", "EventBridge"]] = eventinvokeonsuccess("Type")
Type: Optional[Literal["SQS", "SNS", "Lambda", "EventBridge", "S3Bucket"]] = eventinvokeonsuccess("Type")


class EventInvokeDestinationConfig(BaseModel):
Expand Down Expand Up @@ -178,6 +178,7 @@ class KinesisEventProperties(BaseModel):
StartingPositionTimestamp: Optional[PassThroughProp] = kinesiseventproperties("StartingPositionTimestamp")
Stream: PassThroughProp = kinesiseventproperties("Stream")
TumblingWindowInSeconds: Optional[PassThroughProp] = kinesiseventproperties("TumblingWindowInSeconds")
MetricsConfig: Optional[PassThroughProp]


class KinesisEvent(BaseModel):
Expand All @@ -203,6 +204,7 @@ class DynamoDBEventProperties(BaseModel):
StartingPositionTimestamp: Optional[PassThroughProp] = dynamodbeventproperties("StartingPositionTimestamp")
Stream: PassThroughProp = dynamodbeventproperties("Stream")
TumblingWindowInSeconds: Optional[PassThroughProp] = dynamodbeventproperties("TumblingWindowInSeconds")
MetricsConfig: Optional[PassThroughProp]


class DynamoDBEvent(BaseModel):
Expand Down Expand Up @@ -241,6 +243,7 @@ class SQSEventProperties(BaseModel):
MaximumBatchingWindowInSeconds: Optional[PassThroughProp] = sqseventproperties("MaximumBatchingWindowInSeconds")
Queue: PassThroughProp = sqseventproperties("Queue")
ScalingConfig: Optional[PassThroughProp] # Update docs when live
MetricsConfig: Optional[PassThroughProp]


class SQSEvent(BaseModel):
Expand Down Expand Up @@ -515,6 +518,7 @@ class ScheduleV2Event(BaseModel):
RuntimeManagementConfig = Optional[PassThroughProp] # TODO: check the type
LoggingConfig = Optional[PassThroughProp] # TODO: add documentation
RecursiveLoop = Optional[PassThroughProp]
SourceKMSKeyArn = Optional[PassThroughProp]


class Properties(BaseModel):
Expand Down Expand Up @@ -642,6 +646,7 @@ class Properties(BaseModel):
VpcConfig: Optional[VpcConfig] = prop("VpcConfig")
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation


class Globals(BaseModel):
Expand Down Expand Up @@ -701,6 +706,7 @@ class Globals(BaseModel):
RuntimeManagementConfig: Optional[RuntimeManagementConfig] = prop("RuntimeManagementConfig")
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation


class Resource(ResourceAttributes):
Expand Down
3 changes: 3 additions & 0 deletions samtranslator/model/eventsources/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PullEventSource(ResourceMacro, metaclass=ABCMeta):
"ConsumerGroupId": PropertyType(False, IS_STR),
"ScalingConfig": PropertyType(False, IS_DICT),
"ProvisionedPollerConfig": PropertyType(False, IS_DICT),
"MetricsConfig": PropertyType(False, IS_DICT),
}

BatchSize: Optional[Intrinsicable[int]]
Expand All @@ -80,6 +81,7 @@ class PullEventSource(ResourceMacro, metaclass=ABCMeta):
ConsumerGroupId: Optional[Intrinsicable[str]]
ScalingConfig: Optional[Dict[str, Any]]
ProvisionedPollerConfig: Optional[Dict[str, Any]]
MetricsConfig: Optional[Dict[str, Any]]

@abstractmethod
def get_policy_arn(self) -> Optional[str]:
Expand Down Expand Up @@ -148,6 +150,7 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: P
lambda_eventsourcemapping.KmsKeyArn = self.KmsKeyArn
lambda_eventsourcemapping.ScalingConfig = self.ScalingConfig
lambda_eventsourcemapping.ProvisionedPollerConfig = self.ProvisionedPollerConfig
lambda_eventsourcemapping.MetricsConfig = self.MetricsConfig
self._validate_filter_criteria()

if self.KafkaBootstrapServers:
Expand Down
1 change: 1 addition & 0 deletions samtranslator/model/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class LambdaEventSourceMapping(Resource):
"SelfManagedKafkaEventSourceConfig": GeneratedProperty(),
"ScalingConfig": GeneratedProperty(),
"ProvisionedPollerConfig": GeneratedProperty(),
"MetricsConfig": GeneratedProperty(),
}

runtime_attrs = {"name": lambda self: ref(self.logical_id)}
Expand Down
13 changes: 10 additions & 3 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" SAM macro definitions """
""" SAM macro definitions """

import copy
from contextlib import suppress
Expand Down Expand Up @@ -181,6 +181,7 @@ class SamFunction(SamResourceMacro):
"RuntimeManagementConfig": PassThroughProperty(False),
"LoggingConfig": PassThroughProperty(False),
"RecursiveLoop": PassThroughProperty(False),
"SourceKMSKeyArn": PassThroughProperty(False),
}

FunctionName: Optional[Intrinsicable[str]]
Expand Down Expand Up @@ -224,6 +225,7 @@ class SamFunction(SamResourceMacro):
FunctionUrlConfig: Optional[Dict[str, Any]]
LoggingConfig: Optional[Dict[str, Any]]
RecursiveLoop: Optional[str]
SourceKMSKeyArn: Optional[str]

event_resolver = ResourceTypeResolver(
samtranslator.model.eventsources,
Expand Down Expand Up @@ -439,7 +441,7 @@ def _validate_and_inject_resource(
ARN property, so to handle conditional ifs we have to inject if conditions in the auto created
SQS/SNS resources as well as in the policy documents.
"""
accepted_types_list = ["SQS", "SNS", "EventBridge", "Lambda"]
accepted_types_list = ["SQS", "SNS", "EventBridge", "Lambda", "S3Bucket"]
auto_inject_list = ["SQS", "SNS"]
resource: Optional[Union[SNSTopic, SQSQueue]] = None
policy = {}
Expand Down Expand Up @@ -630,6 +632,8 @@ def _add_event_invoke_managed_policy(
return IAMRolePolicies.event_bus_put_events_role_policy(dest_arn, logical_id)
if _type == "Lambda":
return IAMRolePolicies.lambda_invoke_function_role_policy(dest_arn, logical_id)
if _type == "S3Bucket":
return IAMRolePolicies.s3_send_event_payload_role_policy(dest_arn, logical_id)
return {}

def _construct_role(
Expand Down Expand Up @@ -885,7 +889,10 @@ def _construct_inline_code(*args: Any, **kwargs: Dict[str, Any]) -> Dict[str, An
else:
raise InvalidResourceException(self.logical_id, "Either 'InlineCode' or 'CodeUri' must be set.")
dispatch_function: Callable[..., Dict[str, Any]] = artifact_dispatch[filtered_key]
return dispatch_function(artifacts[filtered_key], self.logical_id, filtered_key)
code_dict = dispatch_function(artifacts[filtered_key], self.logical_id, filtered_key)
if self.SourceKMSKeyArn and packagetype == ZIP:
code_dict["SourceKMSKeyArn"] = self.SourceKMSKeyArn
return code_dict

def _construct_version( # noqa: PLR0912
self,
Expand Down
3 changes: 2 additions & 1 deletion samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Globals:
"RuntimeManagementConfig",
"LoggingConfig",
"RecursiveLoop",
"SourceKMSKeyArn",
],
# Everything except
# DefinitionBody: because its hard to reason about merge of Swagger dictionaries
Expand Down Expand Up @@ -100,7 +101,7 @@ class Globals:
}
# unreleased_properties *must be* part of supported_properties too
unreleased_properties: Dict[str, List[str]] = {
SamResourceType.Function.value: ["RuntimeManagementConfig", "RecursiveLoop"],
SamResourceType.Function.value: ["RuntimeManagementConfig", "RecursiveLoop", "SourceKMSKeyArn"],
}

def __init__(self, template: Dict[str, Any]) -> None:
Expand Down
21 changes: 19 additions & 2 deletions samtranslator/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -274755,6 +274755,9 @@
"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\\.",
"title": "MaximumRetryAttempts"
},
"MetricsConfig": {
"$ref": "#/definitions/PassThroughProp"
},
"ParallelizationFactor": {
"allOf": [
{
Expand Down Expand Up @@ -274990,7 +274993,8 @@
"SQS",
"SNS",
"Lambda",
"EventBridge"
"EventBridge",
"S3Bucket"
],
"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\\.",
"title": "Type",
Expand Down Expand Up @@ -275020,7 +275024,8 @@
"SQS",
"SNS",
"Lambda",
"EventBridge"
"EventBridge",
"S3Bucket"
],
"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\\.",
"title": "Type",
Expand Down Expand Up @@ -275502,6 +275507,9 @@
"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\\.",
"title": "MaximumRetryAttempts"
},
"MetricsConfig": {
"$ref": "#/definitions/PassThroughProp"
},
"ParallelizationFactor": {
"allOf": [
{
Expand Down Expand Up @@ -276778,6 +276786,9 @@
"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\\.",
"title": "MaximumBatchingWindowInSeconds"
},
"MetricsConfig": {
"$ref": "#/definitions/PassThroughProp"
},
"Queue": {
"allOf": [
{
Expand Down Expand Up @@ -278791,6 +278802,9 @@
"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\\.",
"title": "SnapStart"
},
"SourceKMSKeyArn": {
"$ref": "#/definitions/PassThroughProp"
},
"Tags": {
"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\\.",
"title": "Tags",
Expand Down Expand Up @@ -279185,6 +279199,9 @@
"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\\.",
"title": "SnapStart"
},
"SourceKMSKeyArn": {
"$ref": "#/definitions/PassThroughProp"
},
"Tags": {
"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\\.",
"title": "Tags",
Expand Down
Loading

0 comments on commit bd88284

Please sign in to comment.