Skip to content

Commit ca4ddcb

Browse files
authored
Merge pull request #3676 from aws/tmp/1731113614/main
Merge main to develop
2 parents 158c674 + 1b24618 commit ca4ddcb

15 files changed

+432
-21
lines changed

.cfnlintrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ ignore_templates:
131131
- 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]
132132
- 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]
133133
- tests/translator/output/**/function_with_recursive_loop.json # Invalid Property Resources/RecursiveLoopParameterFunction/Properties/RecursiveLoop
134+
- tests/translator/output/**/function_with_sourcekmskeyarn.json # Invalid Property Resources/SourceKMSKeyArnParameterFunction/Properties/SourceKMSKeyArn
134135
- tests/translator/output/**/function_with_tracing.json # Obsolete DependsOn on resource
135136
- tests/translator/output/**/api_with_propagate_tags.json # TODO: Intentional error transform tests. Will be updated.
136137
- tests/translator/output/**/function_with_intrinsics_resource_attribute.json # CFN now supports intrinsics in DeletionPolicy

samtranslator/__init__.py

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

samtranslator/internal/schema_source/aws_serverless_function.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ class ScheduleV2Event(BaseModel):
513513
RuntimeManagementConfig = Optional[PassThroughProp] # TODO: check the type
514514
LoggingConfig = Optional[PassThroughProp] # TODO: add documentation
515515
RecursiveLoop = Optional[PassThroughProp]
516+
SourceKMSKeyArn = Optional[PassThroughProp]
516517

517518

518519
class Properties(BaseModel):
@@ -640,6 +641,7 @@ class Properties(BaseModel):
640641
VpcConfig: Optional[VpcConfig] = prop("VpcConfig")
641642
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
642643
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
644+
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
643645

644646

645647
class Globals(BaseModel):
@@ -699,6 +701,7 @@ class Globals(BaseModel):
699701
RuntimeManagementConfig: Optional[RuntimeManagementConfig] = prop("RuntimeManagementConfig")
700702
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
701703
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
704+
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
702705

703706

704707
class Resource(ResourceAttributes):

samtranslator/model/sam_resources.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class SamFunction(SamResourceMacro):
181181
"RuntimeManagementConfig": PassThroughProperty(False),
182182
"LoggingConfig": PassThroughProperty(False),
183183
"RecursiveLoop": PassThroughProperty(False),
184+
"SourceKMSKeyArn": PassThroughProperty(False),
184185
}
185186

186187
FunctionName: Optional[Intrinsicable[str]]
@@ -224,6 +225,7 @@ class SamFunction(SamResourceMacro):
224225
FunctionUrlConfig: Optional[Dict[str, Any]]
225226
LoggingConfig: Optional[Dict[str, Any]]
226227
RecursiveLoop: Optional[str]
228+
SourceKMSKeyArn: Optional[str]
227229

228230
event_resolver = ResourceTypeResolver(
229231
samtranslator.model.eventsources,
@@ -885,7 +887,10 @@ def _construct_inline_code(*args: Any, **kwargs: Dict[str, Any]) -> Dict[str, An
885887
else:
886888
raise InvalidResourceException(self.logical_id, "Either 'InlineCode' or 'CodeUri' must be set.")
887889
dispatch_function: Callable[..., Dict[str, Any]] = artifact_dispatch[filtered_key]
888-
return dispatch_function(artifacts[filtered_key], self.logical_id, filtered_key)
890+
code_dict = dispatch_function(artifacts[filtered_key], self.logical_id, filtered_key)
891+
if self.SourceKMSKeyArn and packagetype == ZIP:
892+
code_dict["SourceKMSKeyArn"] = self.SourceKMSKeyArn
893+
return code_dict
889894

890895
def _construct_version( # noqa: PLR0912
891896
self,

samtranslator/plugins/globals/globals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Globals:
5555
"RuntimeManagementConfig",
5656
"LoggingConfig",
5757
"RecursiveLoop",
58+
"SourceKMSKeyArn",
5859
],
5960
# Everything except
6061
# DefinitionBody: because its hard to reason about merge of Swagger dictionaries
@@ -100,7 +101,7 @@ class Globals:
100101
}
101102
# unreleased_properties *must be* part of supported_properties too
102103
unreleased_properties: Dict[str, List[str]] = {
103-
SamResourceType.Function.value: ["RuntimeManagementConfig", "RecursiveLoop"],
104+
SamResourceType.Function.value: ["RuntimeManagementConfig", "RecursiveLoop", "SourceKMSKeyArn"],
104105
}
105106

106107
def __init__(self, template: Dict[str, Any]) -> None:

samtranslator/schema/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278785,6 +278785,9 @@
278785278785
"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\\.",
278786278786
"title": "SnapStart"
278787278787
},
278788+
"SourceKMSKeyArn": {
278789+
"$ref": "#/definitions/PassThroughProp"
278790+
},
278788278791
"Tags": {
278789278792
"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\\.",
278790278793
"title": "Tags",
@@ -279179,6 +279182,9 @@
279179279182
"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\\.",
279180279183
"title": "SnapStart"
279181279184
},
279185+
"SourceKMSKeyArn": {
279186+
"$ref": "#/definitions/PassThroughProp"
279187+
},
279182279188
"Tags": {
279183279189
"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\\.",
279184279190
"title": "Tags",

schema_source/sam.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5528,6 +5528,9 @@
55285528
"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\\.",
55295529
"title": "SnapStart"
55305530
},
5531+
"SourceKMSKeyArn": {
5532+
"$ref": "#/definitions/PassThroughProp"
5533+
},
55315534
"Tags": {
55325535
"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\\.",
55335536
"title": "Tags",
@@ -6113,6 +6116,9 @@
61136116
"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\\.",
61146117
"title": "SnapStart"
61156118
},
6119+
"SourceKMSKeyArn": {
6120+
"$ref": "#/definitions/PassThroughProp"
6121+
},
61166122
"Tags": {
61176123
"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\\.",
61186124
"title": "Tags",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Parameters:
2+
SourceKMSKeyArnParam:
3+
Type: String
4+
Default: arn:aws:kms:us-west-2:123456789012:key/dec86919-7219-4e8d-8871-7f1609df2c7f
5+
6+
Resources:
7+
SourceKMSKeyArnFunction:
8+
Type: AWS::Serverless::Function
9+
Properties:
10+
CodeUri: s3://sam-demo-bucket/hello.zip
11+
Handler: hello.handler
12+
Runtime: python3.9
13+
SourceKMSKeyArn: arn:aws:kms:us-west-2:987654321098:key/dec86919-7219-4e8d-8871-7f1609df2c7f
14+
15+
SourceKMSKeyArnParameterFunction:
16+
Type: AWS::Serverless::Function
17+
Properties:
18+
CodeUri: s3://sam-demo-bucket/hello.zip
19+
Handler: hello.handler
20+
Runtime: python3.9
21+
SourceKMSKeyArn: !Ref SourceKMSKeyArnParam

tests/translator/input/globals_for_function.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Globals:
3333
LoggingConfig:
3434
LogGroup: myJsonStructuredLogs
3535
RecursiveLoop: ALLOW
36+
SourceKMSKeyArn: arn:aws:kms:us-west-2:123456789012:key/dec86919-7219-4e8d-8871-7f1609df2c7f
3637

3738

3839

@@ -67,3 +68,4 @@ Resources:
6768
RuntimeManagementConfig:
6869
UpdateRuntimeOn: FunctionChange
6970
RecursiveLoop: TERMINATE
71+
SourceKMSKeyArn: arn:aws:kms:us-west-2:987654321098:key/dec86919-7219-4e8d-8871-7f1609df2c7f
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"Parameters": {
3+
"SourceKMSKeyArnParam": {
4+
"Default": "arn:aws:kms:us-west-2:123456789012:key/dec86919-7219-4e8d-8871-7f1609df2c7f",
5+
"Type": "String"
6+
}
7+
},
8+
"Resources": {
9+
"SourceKMSKeyArnFunction": {
10+
"Properties": {
11+
"Code": {
12+
"S3Bucket": "sam-demo-bucket",
13+
"S3Key": "hello.zip",
14+
"SourceKMSKeyArn": "arn:aws:kms:us-west-2:987654321098:key/dec86919-7219-4e8d-8871-7f1609df2c7f"
15+
},
16+
"Handler": "hello.handler",
17+
"Role": {
18+
"Fn::GetAtt": [
19+
"SourceKMSKeyArnFunctionRole",
20+
"Arn"
21+
]
22+
},
23+
"Runtime": "python3.9",
24+
"Tags": [
25+
{
26+
"Key": "lambda:createdBy",
27+
"Value": "SAM"
28+
}
29+
]
30+
},
31+
"Type": "AWS::Lambda::Function"
32+
},
33+
"SourceKMSKeyArnFunctionRole": {
34+
"Properties": {
35+
"AssumeRolePolicyDocument": {
36+
"Statement": [
37+
{
38+
"Action": [
39+
"sts:AssumeRole"
40+
],
41+
"Effect": "Allow",
42+
"Principal": {
43+
"Service": [
44+
"lambda.amazonaws.com"
45+
]
46+
}
47+
}
48+
],
49+
"Version": "2012-10-17"
50+
},
51+
"ManagedPolicyArns": [
52+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
53+
],
54+
"Tags": [
55+
{
56+
"Key": "lambda:createdBy",
57+
"Value": "SAM"
58+
}
59+
]
60+
},
61+
"Type": "AWS::IAM::Role"
62+
},
63+
"SourceKMSKeyArnParameterFunction": {
64+
"Properties": {
65+
"Code": {
66+
"S3Bucket": "sam-demo-bucket",
67+
"S3Key": "hello.zip",
68+
"SourceKMSKeyArn": {
69+
"Ref": "SourceKMSKeyArnParam"
70+
}
71+
},
72+
"Handler": "hello.handler",
73+
"Role": {
74+
"Fn::GetAtt": [
75+
"SourceKMSKeyArnParameterFunctionRole",
76+
"Arn"
77+
]
78+
},
79+
"Runtime": "python3.9",
80+
"Tags": [
81+
{
82+
"Key": "lambda:createdBy",
83+
"Value": "SAM"
84+
}
85+
]
86+
},
87+
"Type": "AWS::Lambda::Function"
88+
},
89+
"SourceKMSKeyArnParameterFunctionRole": {
90+
"Properties": {
91+
"AssumeRolePolicyDocument": {
92+
"Statement": [
93+
{
94+
"Action": [
95+
"sts:AssumeRole"
96+
],
97+
"Effect": "Allow",
98+
"Principal": {
99+
"Service": [
100+
"lambda.amazonaws.com"
101+
]
102+
}
103+
}
104+
],
105+
"Version": "2012-10-17"
106+
},
107+
"ManagedPolicyArns": [
108+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
109+
],
110+
"Tags": [
111+
{
112+
"Key": "lambda:createdBy",
113+
"Value": "SAM"
114+
}
115+
]
116+
},
117+
"Type": "AWS::IAM::Role"
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)