Generated Amazon CloudFormation resources
This section provides details on the Amazon CloudFormation resources that are created when Amazon SAM processes your Amazon template. The set of Amazon CloudFormation resources that Amazon SAM generates differs depending on the scenarios you specify. A scenario is the combination of Amazon SAM resources and properties specified in your template file. You can reference the generated Amazon CloudFormation resources elsewhere within your template file, similar to how you reference resources that you declare explicitly in your template file.
For example, if you specify an AWS::Serverless::Function
resource in your Amazon SAM
template file, Amazon SAM always generates an AWS::Lambda::Function
base resource. If
you also specify the optional AutoPublishAlias
property, Amazon SAM additionally
generates AWS::Lambda::Alias
and AWS::Lambda::Version
resources.
This section lists the scenarios and the Amazon CloudFormation resources that they generate, and shows how to reference the generated Amazon CloudFormation resources in your Amazon SAM template file.
Referencing generated Amazon CloudFormation resources
You have two options for referencing generated Amazon CloudFormation resources within your Amazon SAM template
file, by LogicalId
or by referenceable property.
Referencing generated Amazon CloudFormation resources by LogicalId
The Amazon CloudFormation resources that Amazon SAM generates each have a LogicalId
, which is an alphanumeric (A-Z, a-z, 0-9) identifier that is
unique within a template file. Amazon SAM uses the LogicalIds
of the Amazon SAM resources
in your template file to construct the LogicalIds
of the Amazon CloudFormation resources it
generates. You can use the LogicalId
of a generated Amazon CloudFormation resource to access
properties of that resource within your template file, just like you would for an Amazon CloudFormation
resource that you have explicitly declared. For more information about
LogicalIds
in Amazon CloudFormation and Amazon SAM templates, see Resources in the
Amazon CloudFormation User Guide.
Note
The LogicalIds
of some generated resources include a unique hash value to
avoid namespace clashes. The LogicalIds
of these resources are derived when
the stack is created. You can retrieve them only after the stack has been created using
the Amazon Web Services Management Console, Amazon CLI, or one of the Amazon SDKs. We don't recommend referencing these
resources by LogicalId
because the hash values might change.
Referencing generated Amazon CloudFormation resources by referenceable property
For some generated resources, Amazon SAM provides a referenceable property of the Amazon SAM resource. You can use this property to reference a generated Amazon CloudFormation resource and its properties within your Amazon SAM template file.
Note
Not all generated Amazon CloudFormation resources have referenceable properties. For those resources,
you must use the LogicalId
.
Generated Amazon CloudFormation resource scenarios
The following table summarizes the Amazon SAM resources and properties that make up the scenarios that generate Amazon CloudFormation resources. The topics in the Scenarios column provide details about the additional Amazon CloudFormation resources that Amazon SAM generates for that scenario.
Amazon SAM resource | Base Amazon CloudFormation resource | Scenarios |
---|---|---|
AWS::Serverless::Api
|
AWS::ApiGateway::RestApi |
|
AWS::Serverless::Application
|
AWS::CloudFormation::Stack |
|
AWS::Serverless::Function |
AWS::Lambda::Function |
|
AWS::Serverless::HttpApi |
AWS::ApiGatewayV2::Api |
|
AWS::Serverless::LayerVersion
|
AWS::Lambda::LayerVersion |
|
AWS::Serverless::SimpleTable
|
AWS::DynamoDB::Table |
|
AWS::Serverless::StateMachine
|
AWS::StepFunctions::StateMachine |
Topics
- Amazon CloudFormation resources generated when AWS::Serverless::Api is specified
- Amazon CloudFormation resources generated when AWS::Serverless::Application is specified
- Amazon CloudFormation resources generated when you specify AWS::Serverless::Connector
- Amazon CloudFormation resources generated when AWS::Serverless::Function is specified
- Amazon CloudFormation resources generated when AWS::Serverless::GraphQLApi is specified
- Amazon CloudFormation resources generated when AWS::Serverless::HttpApi is specified
- Amazon CloudFormation resources generated when AWS::Serverless::LayerVersion is specified
- Amazon CloudFormation resources generated when AWS::Serverless::SimpleTable is specified
- Amazon CloudFormation resources generated when AWS::Serverless::StateMachine is specified