Skip to content

Commit 9b9ff31

Browse files
benbridtsmoelasmar
andauthored
Add support for CloudFormation ModuleVersion and ResourceVersion uploads (aws#2667)
Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>
1 parent f5ba707 commit 9b9ff31

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed

samcli/commands/_utils/resources.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
AWS_LAMBDA_FUNCTION = "AWS::Lambda::Function"
1515
AWS_APIGATEWAY_RESTAPI = "AWS::ApiGateway::RestApi"
1616
AWS_ELASTICBEANSTALK_APPLICATIONVERSION = "AWS::ElasticBeanstalk::ApplicationVersion"
17+
AWS_CLOUDFORMATION_MODULEVERSION = "AWS::CloudFormation::ModuleVersion"
18+
AWS_CLOUDFORMATION_RESOURCEVERSION = "AWS::CloudFormation::ResourceVersion"
1719
AWS_CLOUDFORMATION_STACK = "AWS::CloudFormation::Stack"
1820
AWS_SERVERLESS_APPLICATION = "AWS::Serverless::Application"
1921
AWS_LAMBDA_LAYERVERSION = "AWS::Lambda::LayerVersion"
@@ -35,6 +37,8 @@
3537
AWS_LAMBDA_FUNCTION: ["Code"],
3638
AWS_APIGATEWAY_RESTAPI: ["BodyS3Location"],
3739
AWS_ELASTICBEANSTALK_APPLICATIONVERSION: ["SourceBundle"],
40+
AWS_CLOUDFORMATION_MODULEVERSION: ["ModulePackage"],
41+
AWS_CLOUDFORMATION_RESOURCEVERSION: ["SchemaHandlerPackage"],
3842
AWS_CLOUDFORMATION_STACK: ["TemplateURL"],
3943
AWS_SERVERLESS_APPLICATION: ["Location"],
4044
AWS_LAMBDA_LAYERVERSION: ["Content"],

samcli/lib/package/packageable_resources.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
AWS_SERVERLESS_LAYERVERSION,
4141
AWS_GLUE_JOB,
4242
AWS_STEPFUNCTIONS_STATEMACHINE,
43+
AWS_CLOUDFORMATION_MODULEVERSION,
44+
AWS_CLOUDFORMATION_RESOURCEVERSION,
4345
METADATA_WITH_LOCAL_PATHS,
4446
RESOURCES_WITH_LOCAL_PATHS,
4547
RESOURCES_WITH_IMAGE_COMPONENT,
@@ -423,6 +425,16 @@ class GlueJobCommandScriptLocationResource(ResourceZip):
423425
PROPERTY_NAME = RESOURCES_WITH_LOCAL_PATHS[AWS_GLUE_JOB][0]
424426

425427

428+
class CloudFormationModuleVersionModulePackage(ResourceZip):
429+
RESOURCE_TYPE = AWS_CLOUDFORMATION_MODULEVERSION
430+
PROPERTY_NAME = RESOURCES_WITH_LOCAL_PATHS[AWS_CLOUDFORMATION_MODULEVERSION][0]
431+
432+
433+
class CloudFormationResourceVersionSchemaHandlerPackage(ResourceZip):
434+
RESOURCE_TYPE = AWS_CLOUDFORMATION_RESOURCEVERSION
435+
PROPERTY_NAME = RESOURCES_WITH_LOCAL_PATHS[AWS_CLOUDFORMATION_RESOURCEVERSION][0]
436+
437+
426438
RESOURCES_EXPORT_LIST = [
427439
ServerlessFunctionResource,
428440
ServerlessFunctionImageResource,
@@ -442,6 +454,8 @@ class GlueJobCommandScriptLocationResource(ResourceZip):
442454
ServerlessLayerVersionResource,
443455
LambdaLayerVersionResource,
444456
GlueJobCommandScriptLocationResource,
457+
CloudFormationModuleVersionModulePackage,
458+
CloudFormationResourceVersionSchemaHandlerPackage,
445459
]
446460

447461
METADATA_EXPORT_LIST = [ServerlessRepoApplicationReadme, ServerlessRepoApplicationLicense]

tests/integration/package/test_package_command_zip.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def test_package_template_flag(self, template_file):
5252
"aws-lambda-function.yaml",
5353
"aws-apigateway-restapi.yaml",
5454
"aws-elasticbeanstalk-applicationversion.yaml",
55+
"aws-cloudformation-moduleversion.yaml",
56+
"aws-cloudformation-resourceversion.yaml",
5557
"aws-cloudformation-stack.yaml",
5658
"aws-serverless-application.yaml",
5759
"aws-lambda-layerversion.yaml",
@@ -99,6 +101,8 @@ def test_package_without_required_args(self):
99101
"aws-lambda-function.yaml",
100102
"aws-apigateway-restapi.yaml",
101103
"aws-elasticbeanstalk-applicationversion.yaml",
104+
"aws-cloudformation-moduleversion.yaml",
105+
"aws-cloudformation-resourceversion.yaml",
102106
"aws-cloudformation-stack.yaml",
103107
"aws-serverless-application.yaml",
104108
"aws-lambda-layerversion.yaml",
@@ -139,6 +143,8 @@ def test_package_with_prefix(self, template_file):
139143
"aws-lambda-function.yaml",
140144
"aws-apigateway-restapi.yaml",
141145
"aws-elasticbeanstalk-applicationversion.yaml",
146+
"aws-cloudformation-moduleversion.yaml",
147+
"aws-cloudformation-resourceversion.yaml",
142148
"aws-cloudformation-stack.yaml",
143149
"aws-serverless-application.yaml",
144150
"aws-lambda-layerversion.yaml",
@@ -191,6 +197,8 @@ def test_package_with_output_template_file(self, template_file):
191197
"aws-lambda-function.yaml",
192198
"aws-apigateway-restapi.yaml",
193199
"aws-elasticbeanstalk-applicationversion.yaml",
200+
"aws-cloudformation-moduleversion.yaml",
201+
"aws-cloudformation-resourceversion.yaml",
194202
"aws-cloudformation-stack.yaml",
195203
"aws-serverless-application.yaml",
196204
"aws-lambda-layerversion.yaml",
@@ -244,6 +252,8 @@ def test_package_with_json(self, template_file):
244252
"aws-lambda-function.yaml",
245253
"aws-apigateway-restapi.yaml",
246254
"aws-elasticbeanstalk-applicationversion.yaml",
255+
"aws-cloudformation-moduleversion.yaml",
256+
"aws-cloudformation-resourceversion.yaml",
247257
"aws-cloudformation-stack.yaml",
248258
"aws-serverless-application.yaml",
249259
"aws-lambda-layerversion.yaml",
@@ -299,6 +309,8 @@ def test_package_with_force_upload(self, template_file):
299309
"aws-lambda-function.yaml",
300310
"aws-apigateway-restapi.yaml",
301311
"aws-elasticbeanstalk-applicationversion.yaml",
312+
"aws-cloudformation-moduleversion.yaml",
313+
"aws-cloudformation-resourceversion.yaml",
302314
"aws-cloudformation-stack.yaml",
303315
"aws-serverless-application.yaml",
304316
"aws-lambda-layerversion.yaml",
@@ -352,6 +364,8 @@ def test_package_with_kms_key(self, template_file):
352364
"aws-lambda-function.yaml",
353365
"aws-apigateway-restapi.yaml",
354366
"aws-elasticbeanstalk-applicationversion.yaml",
367+
"aws-cloudformation-moduleversion.yaml",
368+
"aws-cloudformation-resourceversion.yaml",
355369
"aws-cloudformation-stack.yaml",
356370
"aws-serverless-application.yaml",
357371
"aws-lambda-layerversion.yaml",
@@ -404,6 +418,8 @@ def test_package_with_metadata(self, template_file):
404418
"aws-lambda-function.yaml",
405419
"aws-apigateway-restapi.yaml",
406420
"aws-elasticbeanstalk-applicationversion.yaml",
421+
"aws-cloudformation-moduleversion.yaml",
422+
"aws-cloudformation-resourceversion.yaml",
407423
"aws-cloudformation-stack.yaml",
408424
"aws-serverless-application.yaml",
409425
"aws-lambda-layerversion.yaml",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
AWSTemplateFormatVersion : '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: Simple Stack
4+
5+
Resources:
6+
MyResourceVersion:
7+
Type: AWS::CloudFormation::ModuleVersion
8+
Properties:
9+
ModulePackage: ./sourcebundle.zip
10+
ModuleName: Company::Service::Module
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
AWSTemplateFormatVersion : '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: Simple Stack
4+
5+
Resources:
6+
MyResourceVersion:
7+
Type: AWS::CloudFormation::ResourceVersion
8+
Properties:
9+
SchemaHandlerPackage: ./sourcebundle.zip
10+
TypeName: Company::Service::Resource

tests/unit/lib/package/test_artifact_exporter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
AppSyncFunctionConfigurationRequestTemplateResource,
4848
AppSyncFunctionConfigurationResponseTemplateResource,
4949
GlueJobCommandScriptLocationResource,
50+
CloudFormationModuleVersionModulePackage,
51+
CloudFormationResourceVersionSchemaHandlerPackage,
5052
ResourceZip,
5153
ResourceImage,
5254
)
@@ -93,6 +95,8 @@ def test_all_resources_export(self):
9395
{"class": ServerlessRepoApplicationLicense, "expected_result": uploaded_s3_url},
9496
{"class": ServerlessRepoApplicationLicense, "expected_result": uploaded_s3_url},
9597
{"class": GlueJobCommandScriptLocationResource, "expected_result": {"ScriptLocation": uploaded_s3_url}},
98+
{"class": CloudFormationModuleVersionModulePackage, "expected_result": uploaded_s3_url},
99+
{"class": CloudFormationResourceVersionSchemaHandlerPackage, "expected_result": uploaded_s3_url},
96100
]
97101

98102
with patch("samcli.lib.package.packageable_resources.upload_local_artifacts") as upload_local_artifacts_mock:

0 commit comments

Comments
 (0)