

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# AWS SAM テンプレートの構造
<a name="sam-specification-template-anatomy"></a>

 AWS SAM テンプレートファイルは、 CloudFormation 「 *AWS CloudFormation ユーザーガイド*」の「テンプレート構造」で[説明されているテンプレート](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html)ファイルの形式に厳密に従います。 AWS SAM テンプレートファイルと CloudFormation テンプレートファイルの主な違いは次のとおりです。
+ **変換の宣言。**`Transform: AWS::Serverless-2016-10-31` 宣言は AWS SAM テンプレートファイルに必須です。この宣言は、 CloudFormation テンプレートファイルをテンプレートファイルとして識別します AWS SAM 。Transform の詳細については、*AWS CloudFormation ユーザーガイド*の「[Transform](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html)」を参照してください。
+ **Globals セクション。**`Globals` セクションは に固有です AWS SAM。これは、すべてのサーバーレス関数と API に共通するプロパティを定義します。`AWS::Serverless::Function`、、`AWS::Serverless::Api`、`AWS::Serverless::CapacityProvider`、`AWS::Serverless::HttpApi`、および `AWS::Serverless::StateMachine`リソースはすべて`AWS::Serverless::SimpleTable`、 `Globals`セクションで定義されているプロパティを継承します。このセクションの詳細については、「[AWS SAM テンプレートのグローバルセクション](sam-specification-template-anatomy-globals.md)」を参照してください。
+ **Resources セクション。** AWS SAM テンプレートでは、 `Resources`セクションに CloudFormation リソースと AWS SAM リソースの組み合わせを含めることができます。 CloudFormation リソースの詳細については、「 *AWS CloudFormation ユーザーガイド*」の[AWS 「リソースタイプとプロパティタイプのリファレンス](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html)」を参照してください。 AWS SAM リソースの詳細については、「」を参照してください[AWS SAM リソースとプロパティ](sam-specification-resources-and-properties.md)。

 AWS SAM テンプレートファイルの他のすべてのセクションは、同じ名前の CloudFormation テンプレートファイルセクションに対応しています。

## YAML
<a name="template-anatomy-outline.yaml"></a>

以下の例は、YAML 形式のテンプレートフラグメントを示しています。

```
Transform: AWS::Serverless-2016-10-31

Globals:
  set of globals

Description:
  String

Metadata:
  template metadata

Parameters:
  set of parameters

Mappings:
  set of mappings

Conditions:
  set of conditions

Resources:
  set of resources

Outputs:
  set of outputs
```

## テンプレートセクション
<a name="template-anatomy-sections"></a>

AWS SAM テンプレートには、いくつかの主要なセクションを含めることができます。必須のセクションは、`Transform` と `Resources` のみです。

テンプレートセクションは任意の順序で含めることができますが、ただし次の例に示すように、言語拡張機能を使用する場合には、サーバーレス変換の前 (`AWS::Serverless-2016-10-31` の前) に `AWS::LanguageExtensions` を追加する必要があります。

```
Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31
```

テンプレートを作成する際には、以下の一覧が示す論理的な順序の使用が役に立つ場合があります。これは、1 つのセクションの値が前のセクションの値を参照している可能性があるためです。

**[変換 (必須)](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html)**  
 AWS SAM テンプレートの場合は、このセクションに の値を含める必要があります`AWS::Serverless-2016-10-31`。  
追加の transform はオプションです。Transform の詳細については、*AWS CloudFormation ユーザーガイド*の「[Transform](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html)」を参照してください。

**[グローバル (オプション)](sam-specification-template-anatomy-globals.md)**  
すべてのサーバーレス関数、API、および単純テーブルに共通のプロパティです。`AWS::Serverless::Function`、、`AWS::Serverless::Api`、`AWS::Serverless::CapacityProvider`、`AWS::Serverless::HttpApi`、および `AWS::Serverless::StateMachine`リソースはすべて`AWS::Serverless::SimpleTable`、 `Globals`セクションで定義されているプロパティを継承します。  
このセクションは に固有です AWS SAM。 CloudFormation テンプレートに対応するセクションはありません。

**[Description (オプション) ](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-description-structure.html)**  
テンプレートを説明するテキスト文字列です。  
このセクションは、 CloudFormation テンプレートの `Description`セクションに直接対応しています。

**[メタデータ (オプション)](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html)**  
テンプレートに関する追加情報を提供するオブジェクトです。  
このセクションは、 CloudFormation テンプレートの `Metadata`セクションに直接対応しています。

**[パラメータ (任意)](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html)**  
実行時 (スタックを作成または更新するとき) にテンプレートに渡す値です。テンプレートの `Resources` および `Outputs` セクションからのパラメータを参照できます。`Parameters` セクションで宣言されるオブジェクトによって、**sam deploy --guided** コマンドがユーザーに追加のプロンプトを表示するようになります。  
`sam deploy` コマンドの `--parameter-overrides` パラメータ (および設定ファイルのエントリ) を使用することで渡される値で、 AWS SAM テンプレートファイルよりも優先されます。`sam deploy` コマンドの詳細については、 AWS SAM CLI コマンドリファレンスの「[sam deploy](sam-cli-command-reference-sam-deploy.md)」を参照してください。設定ファイルの詳細については、「[AWS SAM CLI 設定ファイル](serverless-sam-cli-config.md)」を参照してください。

**[マッピング (任意)](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html)**  
キーと関連する値のマッピングで、条件パラメータ値の指定に使用でき、ルックアップテーブルに似ています。`Resources` セクションと `Outputs` セクションで [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html) 組み込み関数を使用することによって、キーを対応する値と一致させることができます。  
このセクションは、 CloudFormation テンプレートの `Mappings`セクションに直接対応しています。

**[条件 (オプション)](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html)**  
スタックの作成中または更新中に、特定のリソースが作成されるかどうか、または特定のリソースプロパティに値が割り当てられるかどうかを制御する条件です。例えば、スタックが実稼働用であるかテスト環境用であるかに依存するリソースを、条件付きで作成できます。  
このセクションは、 CloudFormation テンプレートの `Conditions`セクションに直接対応しています。

**[リソース (必須)](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html)**  
Amazon Elastic Compute Cloud (Amazon EC2) インスタンスや Amazon Simple Storage Service (Amazon S3) バケットなどのスタックリソースとそれらのプロパティです。テンプレートの `Resources` と `Outputs` セクションのリソースを参照できます。  
このセクションは、 CloudFormation テンプレートの `Resources` セクションに似ています。 AWS SAM テンプレートでは、このセクションには AWS SAM リソースに加えて CloudFormation リソースを含めることができます。

**[出力 (任意)](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html)**  
スタックのプロパティを表示するたびに返される値です。たとえば、S3 バケット名の出力を宣言し、 `aws cloudformation describe-stacks` AWS Command Line Interface (AWS CLI) コマンドを呼び出して名前を表示できます。  
このセクションは、 CloudFormation テンプレートの `Outputs` セクションに直接対応します。

## 次の手順
<a name="template-anatomy-next-steps"></a>

 AWS SAM テンプレートファイルを含むサンプルサーバーレスアプリケーションをダウンロードしてデプロイするには、[の開始方法 AWS SAM](serverless-getting-started.md)「」を参照して、「」の手順に従います[チュートリアル: を使用して Hello World アプリケーションをデプロイする AWS SAM](serverless-getting-started-hello-world.md)。