Resource attributes supported by AWS SAM
Resource attributes are attributes that you can add to AWS SAM and AWS CloudFormation resources to control additional behaviors and relationships. For more information about resource attributes, see Resource Attribute Reference in the AWS CloudFormation User Guide.
AWS SAM support a subset of resource attributes that are defined by AWS CloudFormation. Of the supported resource attributes, some are copied to only the base generated AWS CloudFormation resource of the corresponding AWS SAM resource, and some are copied to all generated AWS CloudFormation resources resulting from the corresponding AWS SAM resource. For more information about AWS CloudFormation resources generated from corresponding AWS SAM resources, see Generated AWS CloudFormation resources for AWS SAM.
The following table summarizes resource attribute support by AWS SAM, subject to the Exceptions listed below.
Resource attributes | Destination generated resource(s) |
---|---|
Metadata 1, 2 |
Base AWS CloudFormation generated resource only. For information about the mapping between AWS SAM resources and base AWS CloudFormation resources, see Generated AWS CloudFormation resource scenarios. |
All generated AWS CloudFormation resources from the corresponding AWS SAM resource. For information about scenarios for generated AWS CloudFormation resources, see Generated AWS CloudFormation resource scenarios. |
Notes:
-
For more information about using the
Metadata
resource attribute with theAWS::Serverless::Function
resource type, see Building Lambda functions with custom runtimes in AWS SAM. -
For more information about using the
Metadata
resource attribute with theAWS::Serverless::LayerVersion
resource type, see Building Lambda layers in AWS SAM.
Exceptions
There are a number of exceptions to the resource attribute rules described previously:
-
For
AWS::Lambda::LayerVersion
, the AWS SAM-only custom fieldRetentionPolicy
sets theDeletionPolicy
for the generated AWS CloudFormation resources. This has a higher precedence thanDeletionPolicy
itself. If neither is set, then by defaultDeletionPolicy
is set toRetain
. -
For
AWS::Lambda::Version
, ifDeletionPolicy
is not specified, the default isRetain
. -
For the scenario where
DeploymentPreferences
is specified for a serverless function, resource attributes are not copied to the following generated AWS CloudFormation resources:-
AWS::CodeDeploy::Application
-
AWS::CodeDeploy::DeploymentGroup
-
The
AWS::IAM::Role
namedCodeDeployServiceRole
that is created for this scenario
-
-
If your AWS SAM template contains multiple functions with API event sources that are implicitly created, then the functions will share the generated
AWS::ApiGateway::RestApi
resource. In this scenario, if the functions have different resource attributes, then for the generatedAWS::ApiGateway::RestApi
resource, AWS SAM copies the resource attributes according to the following prioritized lists:-
UpdateReplacePolicy
:-
Retain
-
Snapshot
-
Delete
-
-
DeletionPolicy
:-
Retain
-
Delete
-
-