in samtranslator/model/sam_resources.py [0:0]
def _construct_lambda_layer(self, intrinsics_resolver: IntrinsicsResolver) -> LambdaLayerVersion:
"""Constructs and returns the Lambda function.
:returns: a list containing the Lambda function and execution role resources
:rtype: list
"""
# Resolve intrinsics if applicable:
self.LayerName = resolve_string_parameter_in_resource(
self.logical_id, intrinsics_resolver, self.LayerName, "LayerName"
)
self.LicenseInfo = resolve_string_parameter_in_resource(
self.logical_id, intrinsics_resolver, self.LicenseInfo, "LicenseInfo"
)
self.Description = resolve_string_parameter_in_resource(
self.logical_id, intrinsics_resolver, self.Description, "Description"
)
self.RetentionPolicy = resolve_string_parameter_in_resource(
self.logical_id, intrinsics_resolver, self.RetentionPolicy, "RetentionPolicy"
)
# If nothing defined, this will be set to Retain
retention_policy_value = self._get_retention_policy_value()
attributes = self.get_passthrough_resource_attributes()
if "DeletionPolicy" not in attributes:
attributes["DeletionPolicy"] = self.RETAIN
if retention_policy_value is not None:
attributes["DeletionPolicy"] = retention_policy_value
old_logical_id = self.logical_id
# This is to prevent the passthrough resource attributes to be included for hashing
hash_dict = copy.deepcopy(self.to_dict())
if "DeletionPolicy" in hash_dict.get(old_logical_id, {}):
del hash_dict[old_logical_id]["DeletionPolicy"]
if "UpdateReplacePolicy" in hash_dict.get(old_logical_id, {}):
del hash_dict[old_logical_id]["UpdateReplacePolicy"]
if "Metadata" in hash_dict.get(old_logical_id, {}):
del hash_dict[old_logical_id]["Metadata"]
new_logical_id = logical_id_generator.LogicalIdGenerator(old_logical_id, hash_dict).gen()
self.logical_id = new_logical_id
lambda_layer = LambdaLayerVersion(self.logical_id, depends_on=self.depends_on, attributes=attributes)
# Changing the LayerName property: when a layer is published, it is given an Arn
# example: arn:aws:lambda:us-west-2:123456789012:layer:MyLayer:1
# where MyLayer is the LayerName property if it exists; otherwise, it is the
# LogicalId of this resource. Since a LayerVersion is an immutable resource, when
# CloudFormation updates this resource, it will ALWAYS create a new version then
# delete the old version if the logical ids match. What this does is change the
# logical id of every layer (so a `DeletionPolicy: Retain` can work) and set the
# LayerName property of the layer so that the Arn will still always be the same
# with the exception of an incrementing version number.
if not self.LayerName:
self.LayerName = old_logical_id
lambda_layer.LayerName = self.LayerName
lambda_layer.Description = self.Description
lambda_layer.Content = construct_s3_location_object(self.ContentUri, self.logical_id, "ContentUri")
lambda_layer.CompatibleArchitectures = self.CompatibleArchitectures
self._validate_architectures(lambda_layer)
lambda_layer.CompatibleRuntimes = self.CompatibleRuntimes
lambda_layer.LicenseInfo = self.LicenseInfo
return lambda_layer