Skip to content

Commit d5d81b5

Browse files
hawflauslowpokesnailKevin Weng
authored
Feat /tmp config (#125)
* feat: SAM support for /tmp config (#87) * Add EphemeralStorage field Add EphemeralStorage as a new option when creating SAM templates. Add functionality to transform SAM templates with EphemeralStorage to Cloudformation templates. Add /translate tests for new field * Add EphemeralStorage to global configs * Add EphemeralStorage to global configs * Add testing for functions with intrinsic refs, add EphemeralStorage to versions Co-authored-by: Kevin Weng <[email protected]> * chore: add integration test for /tmp (#101) * Add integration test for /tmp Also edit basic_function_event_destinations template file to avoid deprecated runtime error * Add integration test for /tmp Also edit basic_function_event_destinations template file to avoid deprecated runtime error * Revert changes to template runtime and use getters in test_function_with_ephemeral_storage. Delete duplicated test * Revert runtime changes Co-authored-by: Kevin Weng <[email protected]> Co-authored-by: Kevin Weng <[email protected]> Co-authored-by: Kevin Weng <[email protected]>
1 parent 594c54f commit d5d81b5

17 files changed

+458
-3
lines changed

docs/globals.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Currently, the following resources and properties are being supported:
7171
ReservedConcurrentExecutions:
7272
EventInvokeConfig:
7373
Architectures:
74+
EphemeralStorage:
7475
7576
Api:
7677
# Properties of AWS::Serverless::Api
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
{ "LogicalResourceId":"MyLambdaFunction", "ResourceType":"AWS::Lambda::Function" },
3+
{ "LogicalResourceId":"MyLambdaFunctionRole", "ResourceType":"AWS::IAM::Role" }
4+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Resources:
2+
MyLambdaFunction:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
Handler: index.handler
6+
Runtime: nodejs12.x
7+
CodeUri: ${codeuri}
8+
MemorySize: 128
9+
EphemeralStorage:
10+
Size: 1024
11+
Policies:
12+
- AWSLambdaRole
13+
- AmazonS3ReadOnlyAccess
14+
Environment:
15+
Variables:
16+
Name: Value
17+
Name2: Value2

integration/single/test_basic_function.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,22 @@ def test_basic_function_with_tracing(self):
204204
"PassThrough",
205205
"Expecting tracing config mode to be set to PassThrough.",
206206
)
207+
208+
@parameterized.expand(
209+
[
210+
"single/function_with_ephemeral_storage",
211+
]
212+
)
213+
def test_function_with_ephemeral_storage(self, file_name):
214+
"""
215+
Creates a basic function with ephemeral storage
216+
"""
217+
self.create_and_verify_stack(file_name)
218+
219+
function_id = self.get_physical_id_by_logical_id("MyLambdaFunction")
220+
221+
function_configuration_result = self.client_provider.lambda_client.get_function_configuration(
222+
FunctionName=function_id
223+
)
224+
225+
self.assertEqual(function_configuration_result.get("EphemeralStorage", {}).get("Size", 0), 1024)

samtranslator/model/lambda_.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class LambdaFunction(Resource):
2727
"CodeSigningConfigArn": PropertyType(False, is_str()),
2828
"ImageConfig": PropertyType(False, is_type(dict)),
2929
"Architectures": PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),
30+
"EphemeralStorage": PropertyType(False, is_type(dict)),
3031
}
3132

3233
runtime_attrs = {"name": lambda self: ref(self.logical_id), "arn": lambda self: fnGetAtt(self.logical_id, "Arn")}

samtranslator/model/sam_resources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class SamFunction(SamResourceMacro):
8383
"ReservedConcurrentExecutions": PropertyType(False, any_type()),
8484
"Layers": PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),
8585
"EventInvokeConfig": PropertyType(False, is_type(dict)),
86+
"EphemeralStorage": PropertyType(False, is_type(dict)),
8687
# Intrinsic functions in value of Alias property are not supported, yet
8788
"AutoPublishAlias": PropertyType(False, one_of(is_str())),
8889
"AutoPublishCodeSha256": PropertyType(False, one_of(is_str())),
@@ -426,6 +427,7 @@ def _construct_lambda_function(self):
426427
lambda_function.ImageConfig = self.ImageConfig
427428
lambda_function.PackageType = self.PackageType
428429
lambda_function.Architectures = self.Architectures
430+
lambda_function.EphemeralStorage = self.EphemeralStorage
429431

430432
if self.Tracing:
431433
lambda_function.TracingConfig = {"Mode": self.Tracing}

samtranslator/plugins/globals/globals.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Globals(object):
4242
"FileSystemConfigs",
4343
"CodeSigningConfigArn",
4444
"Architectures",
45+
"EphemeralStorage",
4546
],
4647
# Everything except
4748
# DefinitionBody: because its hard to reason about merge of Swagger dictionaries
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Parameters:
2+
EphemeralStorageSizeRef:
3+
Type: Number
4+
Resources:
5+
MinimalFunction:
6+
Type: 'AWS::Serverless::Function'
7+
Properties:
8+
CodeUri: s3://sam-demo-bucket/hello.zip
9+
Handler: hello.handler
10+
Runtime: python2.7
11+
EphemeralStorage:
12+
Size: 1024
13+
FunctionWithIntrinsicRef:
14+
Type: 'AWS::Serverless::Function'
15+
Properties:
16+
CodeUri: s3://sam-demo-bucket/hello.zip
17+
Handler: hello.handler
18+
Runtime: python2.7
19+
EphemeralStorage:
20+
Size: !Ref EphemeralStorageSizeRef

tests/translator/input/globals_for_function.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Globals:
2424
ReservedConcurrentExecutions: 50
2525
Architectures:
2626
- x86_64
27+
EphemeralStorage:
28+
Size: 1024
2729

2830
Resources:
2931
MinimalFunction:
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"Resources": {
3+
"FunctionWithIntrinsicRef": {
4+
"Type": "AWS::Lambda::Function",
5+
"Properties": {
6+
"Code": {
7+
"S3Bucket": "sam-demo-bucket",
8+
"S3Key": "hello.zip"
9+
},
10+
"Tags": [
11+
{
12+
"Value": "SAM",
13+
"Key": "lambda:createdBy"
14+
}
15+
],
16+
"EphemeralStorage": {
17+
"Size": {
18+
"Ref": "EphemeralStorageSizeRef"
19+
}
20+
},
21+
"Handler": "hello.handler",
22+
"Role": {
23+
"Fn::GetAtt": [
24+
"FunctionWithIntrinsicRefRole",
25+
"Arn"
26+
]
27+
},
28+
"Runtime": "python2.7"
29+
}
30+
},
31+
"FunctionWithIntrinsicRefRole": {
32+
"Type": "AWS::IAM::Role",
33+
"Properties": {
34+
"AssumeRolePolicyDocument": {
35+
"Version": "2012-10-17",
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+
},
50+
"ManagedPolicyArns": [
51+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
52+
],
53+
"Tags": [
54+
{
55+
"Value": "SAM",
56+
"Key": "lambda:createdBy"
57+
}
58+
]
59+
}
60+
},
61+
"MinimalFunctionRole": {
62+
"Type": "AWS::IAM::Role",
63+
"Properties": {
64+
"AssumeRolePolicyDocument": {
65+
"Version": "2012-10-17",
66+
"Statement": [
67+
{
68+
"Action": [
69+
"sts:AssumeRole"
70+
],
71+
"Effect": "Allow",
72+
"Principal": {
73+
"Service": [
74+
"lambda.amazonaws.com"
75+
]
76+
}
77+
}
78+
]
79+
},
80+
"ManagedPolicyArns": [
81+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
82+
],
83+
"Tags": [
84+
{
85+
"Value": "SAM",
86+
"Key": "lambda:createdBy"
87+
}
88+
]
89+
}
90+
},
91+
"MinimalFunction": {
92+
"Type": "AWS::Lambda::Function",
93+
"Properties": {
94+
"Code": {
95+
"S3Bucket": "sam-demo-bucket",
96+
"S3Key": "hello.zip"
97+
},
98+
"Tags": [
99+
{
100+
"Value": "SAM",
101+
"Key": "lambda:createdBy"
102+
}
103+
],
104+
"EphemeralStorage": {
105+
"Size": 1024
106+
},
107+
"Handler": "hello.handler",
108+
"Role": {
109+
"Fn::GetAtt": [
110+
"MinimalFunctionRole",
111+
"Arn"
112+
]
113+
},
114+
"Runtime": "python2.7"
115+
}
116+
}
117+
},
118+
"Parameters": {
119+
"EphemeralStorageSizeRef": {
120+
"Type": "Number"
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)