

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 為 產生 CloudFormation 資源 AWS SAM
<a name="sam-specification-generated-resources"></a>

本節提供 AWS SAM 處理 AWS 範本時所建立 CloudFormation 資源的詳細資訊。 AWS SAM 產生的 CloudFormation 資源集會因您指定的案例而有所不同。*案例*是範本檔案中指定的資源和屬性的 AWS SAM 組合。您可以參考範本檔案中其他位置產生的 CloudFormation 資源，類似於您在範本檔案中明確宣告的資源參考方式。

例如，如果您在 AWS SAM 範本檔案中指定`AWS::Serverless::Function`資源， AWS SAM 一律會產生`AWS::Lambda::Function`基本資源。如果您也指定選用`AutoPublishAlias`屬性，則 會 AWS SAM 另外產生 `AWS::Lambda::Version` `AWS::Lambda::Alias`和資源。

本節列出案例及其產生的 CloudFormation 資源，並說明如何參考 AWS SAM 範本檔案中產生的 CloudFormation 資源。

## 參考產生的 CloudFormation 資源
<a name="sam-specification-generated-resources-referencing"></a>

您可以透過 `LogicalId`或 可參考屬性，在 AWS SAM 範本檔案中參考產生的 CloudFormation 資源。

### 參考 LogicalId 產生的 CloudFormation 資源
<a name="sam-specification-generated-resources-referencing-logicalid"></a>

每個 AWS SAM 產生的 CloudFormation 資源都有一個 `[LogicalId](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html#resources-section-structure-logicalid)`，這是範本檔案中唯一的英數字元 (A-Z、a-z、0-9) 識別符。 AWS SAM 會使用範本檔案中`LogicalIds` AWS SAM 的 資源的 來建構其產生的 CloudFormation 資源`LogicalIds`的 。您可以使用產生的 CloudFormation 資源`LogicalId`的 來存取範本檔案中該資源的屬性，就像 CloudFormation 您明確宣告的資源一樣。如需 CloudFormation 和 AWS SAM 範本`LogicalIds`中的詳細資訊，請參閱*AWS CloudFormation 《 使用者指南*》中的[資源](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html)。

**注意**  
部分產生的資源`LogicalIds`包含唯一的雜湊值，以避免命名空間衝突。這些資源`LogicalIds`的 會在建立堆疊時衍生。您只能在使用 AWS 管理主控台 AWS CLI或其中一個 AWS SDKs 建立堆疊之後擷取它們。我們不建議 參考這些資源，`LogicalId`因為雜湊值可能會變更。

### 透過可參考屬性參考產生的 CloudFormation 資源
<a name="sam-specification-generated-resources-referencing-referenceable-property"></a>

對於某些產生的資源， AWS SAM 會提供資源的 AWS SAM 可參考屬性。您可以使用此屬性來參考 AWS SAM 範本檔案中產生的 CloudFormation 資源及其屬性。

**注意**  
並非所有產生的 CloudFormation 資源都有可參考的屬性。對於這些資源，您必須使用 `LogicalId`。

## 產生的 CloudFormation 資源案例
<a name="sam-specification-generated-resources-scenarios"></a>

下表摘要說明組成產生 AWS SAM 資源之案例 CloudFormation 的資源和屬性。**案例**欄中的主題提供有關為該案例產生之其他 CloudFormation 資源 AWS SAM 的詳細資訊。


| AWS SAM 資源 | 基本 CloudFormation 資源 | 案例 | 
| --- | --- | --- | 
| AWS::Serverless::Api  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html) |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::Application  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html) |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::CapacityProvider  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html) |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::Function | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html) |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::HttpApi | [AWS::ApiGatewayV2::Api](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.html) |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::LayerVersion  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html) |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::SimpleTable  | [AWS::DynamoDB::Table](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html) |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::StateMachine  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html) |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 

**Topics**
+ [參考產生的 CloudFormation 資源](#sam-specification-generated-resources-referencing)
+ [產生的 CloudFormation 資源案例](#sam-specification-generated-resources-scenarios)
+ [CloudFormation 指定 AWS::Serverless::Api 時產生的資源](sam-specification-generated-resources-api.md)
+ [CloudFormation 指定 AWS::Serverless::Application 時產生的資源](sam-specification-generated-resources-application.md)
+ [CloudFormation 指定 AWS::Serverless::CapacityProvider 時產生的資源](sam-specification-generated-resources-capacityprovider.md)
+ [CloudFormation 當您指定 時產生的資源 AWS::Serverless::Connector](sam-specification-generated-resources-connector.md)
+ [CloudFormation 指定 AWS::Serverless::Function 時產生的資源](sam-specification-generated-resources-function.md)
+ [CloudFormation 指定 AWS::Serverless::GraphQLApi 時產生的資源](sam-specification-generated-resources-graphqlapi.md)
+ [CloudFormation 指定 AWS::Serverless::HttpApi 時產生的資源](sam-specification-generated-resources-httpapi.md)
+ [CloudFormation 指定 AWS::Serverless::WebSocketApi 時產生的資源](sam-specification-generated-resources-websocketapi.md)
+ [CloudFormation 指定 AWS::Serverless::LayerVersion 時產生的資源](sam-specification-generated-resources-layerversion.md)
+ [CloudFormation 指定 AWS::Serverless::SimpleTable 時產生的資源](sam-specification-generated-resources-simpletable.md)
+ [CloudFormation 指定 AWS::Serverless::StateMachine 時產生的資源](sam-specification-generated-resources-statemachine.md)