Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.54.0"
__version__ = "1.55.0"
1 change: 1 addition & 0 deletions samtranslator/model/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class LambdaFunction(Resource):
"CodeSigningConfigArn": PropertyType(False, is_str()),
"ImageConfig": PropertyType(False, is_type(dict)),
"Architectures": PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),
"SnapStart": PropertyType(False, is_type(dict)),
"EphemeralStorage": PropertyType(False, is_type(dict)),
}

Expand Down
5 changes: 5 additions & 0 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class SamFunction(SamResourceMacro):
"ImageConfig": PropertyType(False, is_type(dict)),
"CodeSigningConfigArn": PropertyType(False, is_str()),
"Architectures": PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),
"SnapStart": PropertyType(False, is_type(dict)),
"FunctionUrlConfig": PropertyType(False, is_type(dict)),
}

Expand Down Expand Up @@ -514,6 +515,7 @@ def _construct_lambda_function(self): # type: ignore[no-untyped-def]
lambda_function.ImageConfig = self.ImageConfig
lambda_function.PackageType = self.PackageType
lambda_function.Architectures = self.Architectures
lambda_function.SnapStart = self.SnapStart # type: ignore[attr-defined]
lambda_function.EphemeralStorage = self.EphemeralStorage

if self.Tracing:
Expand Down Expand Up @@ -864,6 +866,9 @@ def _construct_version(self, function, intrinsics_resolver, code_sha256=None):
logical_dict.update(function.Environment)
if function.MemorySize:
logical_dict.update({"MemorySize": function.MemorySize})
# If SnapStart is enabled we want to publish a new version, to have the corresponding snapshot
if function.SnapStart and function.SnapStart.get("ApplyOn", "None") != "None":
logical_dict.update({"SnapStart": function.SnapStart})
logical_id = logical_id_generator.LogicalIdGenerator(prefix, logical_dict, code_sha256).gen()

attributes = self.get_passthrough_resource_attributes() # type: ignore[no-untyped-call]
Expand Down
5 changes: 4 additions & 1 deletion samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Globals(object):
"FileSystemConfigs",
"CodeSigningConfigArn",
"Architectures",
"SnapStart",
"EphemeralStorage",
"FunctionUrlConfig",
],
Expand Down Expand Up @@ -86,7 +87,9 @@ class Globals(object):
SamResourceType.SimpleTable.value: ["SSESpecification"],
}
# unreleased_properties *must be* part of supported_properties too
unreleased_properties: Dict[str, List[str]] = {}
unreleased_properties: Dict[str, List[str]] = {
SamResourceType.Function.value: ["SnapStart"],
}

def __init__(self, template): # type: ignore[no-untyped-def]
"""
Expand Down
3 changes: 3 additions & 0 deletions samtranslator/schema/aws_serverless_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ class ScheduleV2Event(BaseModel):
AssumeRolePolicyDocument = Optional[DictStrAny]
Architectures = Optional[PassThrough]
EphemeralStorage = Optional[PassThrough]
SnapStart = Optional[PassThrough] # TODO: check the type


class Properties(BaseModel):
Expand Down Expand Up @@ -498,6 +499,7 @@ class Properties(BaseModel):
ReservedConcurrentExecutions: Optional[ReservedConcurrentExecutions] = prop("ReservedConcurrentExecutions")
Role: Optional[SamIntrinsicable[str]] = prop("Role")
Runtime: Optional[Runtime] = prop("Runtime")
SnapStart: Optional[SnapStart] # TODO: add prop and types
Tags: Optional[Tags] = prop("Tags")
Timeout: Optional[Timeout] = prop("Timeout")
Tracing: Optional[Tracing] = prop("Tracing")
Expand Down Expand Up @@ -529,6 +531,7 @@ class Globals(BaseModel):
EventInvokeConfig: Optional[EventInvokeConfig] = prop("EventInvokeConfig")
Architectures: Optional[Architectures] = prop("Architectures")
EphemeralStorage: Optional[EphemeralStorage] = prop("EphemeralStorage")
SnapStart: Optional[SnapStart] # TODO: add prop


class Resource(BaseModel):
Expand Down
6 changes: 6 additions & 0 deletions samtranslator/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@
"title": "EphemeralStorage",
"description": "An object that specifies the disk space, in MB, available to your Lambda function in `/tmp`\\. \nFor more information about this property, see [Lambda execution environment](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html) in the *AWS Lambda Developer Guide*\\. \n*Type*: [EphemeralStorage](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-ephemeralstorage) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`EphemeralStorage`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-ephemeralstorage) property of an `AWS::Lambda::Function` resource\\.",
"markdownDescription": "An object that specifies the disk space, in MB, available to your Lambda function in `/tmp`\\. \nFor more information about this property, see [Lambda execution environment](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html) in the *AWS Lambda Developer Guide*\\. \n*Type*: [EphemeralStorage](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-ephemeralstorage) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`EphemeralStorage`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-ephemeralstorage) property of an `AWS::Lambda::Function` resource\\."
},
"SnapStart": {
"title": "Snapstart"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -3972,6 +3975,9 @@
"description": "The identifier of the function's [runtime](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)\\. This property is only required if the `PackageType` property is set to `Zip`\\. \nIf you specify the `provided` identifier for this property, you can use the `Metadata` resource attribute to instruct AWS SAM to build the custom runtime that this function requires\\. For more information about building custom runtimes, see [Building custom runtimes](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/building-custom-runtimes.html)\\.\n*Type*: String \n*Required*: Conditional \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Runtime`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-runtime) property of an `AWS::Lambda::Function` resource\\.",
"markdownDescription": "The identifier of the function's [runtime](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)\\. This property is only required if the `PackageType` property is set to `Zip`\\. \nIf you specify the `provided` identifier for this property, you can use the `Metadata` resource attribute to instruct AWS SAM to build the custom runtime that this function requires\\. For more information about building custom runtimes, see [Building custom runtimes](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/building-custom-runtimes.html)\\.\n*Type*: String \n*Required*: Conditional \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Runtime`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-runtime) property of an `AWS::Lambda::Function` resource\\."
},
"SnapStart": {
"title": "Snapstart"
},
"Tags": {
"title": "Tags",
"description": "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\\.",
Expand Down
35 changes: 35 additions & 0 deletions tests/translator/input/function_with_snapstart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%YAML 1.1
---
Parameters:
SnapStartParam:
Type: String
Default: None

Resources:
SnapStartFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
SnapStart:
ApplyOn: PublishedVersions

SnapStartParameterFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
SnapStart:
ApplyOn: !Ref SnapStartParam

SnapStartFunctionWithAlias:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
AutoPublishAlias: live
SnapStart:
ApplyOn: PublishedVersions
4 changes: 4 additions & 0 deletions tests/translator/input/globals_for_function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Globals:
ReservedConcurrentExecutions: 50
Architectures:
- x86_64
SnapStart:
ApplyOn: PublishedVersions
EphemeralStorage:
Size: 1024

Expand Down Expand Up @@ -52,4 +54,6 @@ Resources:
PermissionsBoundary: arn:aws:1234:iam:boundary/OverridePermissionsBoundary
Layers:
- !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2
SnapStart:
ApplyOn: None
ReservedConcurrentExecutions: 100
204 changes: 204 additions & 0 deletions tests/translator/output/aws-cn/function_with_snapstart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
{
"Parameters": {
"SnapStartParam": {
"Default": "None",
"Type": "String"
}
},
"Resources": {
"SnapStartFunction": {
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"Role": {
"Fn::GetAtt": [
"SnapStartFunctionRole",
"Arn"
]
},
"Runtime": "python3.9",
"SnapStart": {
"ApplyOn": "PublishedVersions"
},
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"SnapStartFunctionRole": {
"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"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
},
"SnapStartFunctionWithAlias": {
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"Role": {
"Fn::GetAtt": [
"SnapStartFunctionWithAliasRole",
"Arn"
]
},
"Runtime": "python3.9",
"SnapStart": {
"ApplyOn": "PublishedVersions"
},
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"SnapStartFunctionWithAliasAliaslive": {
"Properties": {
"FunctionName": {
"Ref": "SnapStartFunctionWithAlias"
},
"FunctionVersion": {
"Fn::GetAtt": [
"SnapStartFunctionWithAliasVersion0abd29242e",
"Version"
]
},
"Name": "live"
},
"Type": "AWS::Lambda::Alias"
},
"SnapStartFunctionWithAliasRole": {
"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"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
},
"SnapStartFunctionWithAliasVersion0abd29242e": {
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
"Ref": "SnapStartFunctionWithAlias"
}
},
"Type": "AWS::Lambda::Version"
},
"SnapStartParameterFunction": {
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"Role": {
"Fn::GetAtt": [
"SnapStartParameterFunctionRole",
"Arn"
]
},
"Runtime": "python3.9",
"SnapStart": {
"ApplyOn": {
"Ref": "SnapStartParam"
}
},
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"SnapStartParameterFunctionRole": {
"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"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
}
}
}
10 changes: 8 additions & 2 deletions tests/translator/output/aws-cn/globals_for_function.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
]
},
"Runtime": "nodejs12.x",
"SnapStart": {
"ApplyOn": "None"
},
"Tags": [
{
"Key": "lambda:createdBy",
Expand Down Expand Up @@ -165,6 +168,9 @@
]
},
"Runtime": "python2.7",
"SnapStart": {
"ApplyOn": "PublishedVersions"
},
"Tags": [
{
"Key": "lambda:createdBy",
Expand Down Expand Up @@ -197,7 +203,7 @@
},
"FunctionVersion": {
"Fn::GetAtt": [
"MinimalFunctionVersion0a06fc8fb1",
"MinimalFunctionVersione7c6f56e4d",
"Version"
]
},
Expand Down Expand Up @@ -242,7 +248,7 @@
},
"Type": "AWS::IAM::Role"
},
"MinimalFunctionVersion0a06fc8fb1": {
"MinimalFunctionVersione7c6f56e4d": {
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
Expand Down
Loading