

これは新しい CloudFormation テンプレートリファレンスガイドです。ブックマークとリンクを更新してください。CloudFormation の開始方法については、『[AWS CloudFormation ユーザーガイド](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)』を参照してください。

# `AWS::CloudFormation::Authentication`
<a name="aws-resource-authentication"></a>

`AWS::CloudFormation::Authentication` メタデータタイプを使用して、[`AWS::CloudFormation::Init`](aws-resource-init.md) メタデータタイプで指定したファイルまたはソースの認証情報を指定します。

`AWS::CloudFormation::Init` で指定したソースまたはファイルの認証情報を含めるには、ソースが URI の場合は `uris` プロパティを使用し、ソースが Amazon S3 バケットの場合は `buckets` プロパティを使用します。files の詳細については、「[ファイル](aws-resource-init.md#aws-resource-init-files)」を参照してください。sources の詳細については、「[ソース](aws-resource-init.md#aws-resource-init-sources)」を参照してください。

ファイルの認証情報は、`AWS::CloudFormation::Init` メタデータタイプに直接指定することもできます。リソースの files キーには、`authentication` というプロパティが含まれます。`authentication` プロパティを使用すると、`AWS::CloudFormation::Authentication` メタデータタイプに定義された認証情報をファイルに直接関連付けることができます。

ファイルの場合、CloudFormation は次の順序で認証情報を検索します。

1. `authentication` `AWS::CloudFormation::Init` キーの `files` プロパティ。

1. `AWS::CloudFormation::Authentication` メタデータの `uris` または `buckets` プロパティ。

ソースの場合、CloudFormation は、`AWS::CloudFormation::Authentication` メタデータの `uris` プロパティまたは `buckets` プロパティ内で認証情報を検索します。

**Topics**
+ [構文](#aws-resource-cloudformation-authentication-syntax)
+ [プロパティ](#w2aac19c23c15c19)
+ [例](#aws-resource-authentication-examples)

## 構文
<a name="aws-resource-cloudformation-authentication-syntax"></a>

CloudFormation テンプレートでこのエンティティを宣言するには、次の構文を使用します。

`AWS::CloudFormation::Authentication` メタデータタイプを使用するときは、以下の考慮事項に注意してください。
+ ほとんどの CloudFormation リソースとは異なり、`AWS::CloudFormation::Authentication` メタデータタイプには、*[プロパティ]* という名前のブロックが含まれません。その代わりに、ユーザーによって名前が付けられたブロックのリストが含まれます。各ブロックには、それぞれ独自の認証プロパティが含まれます。

  すべてのプロパティが各認証タイプに関連するわけではありません。詳細については、「[type](#cfn-cloudformation-authentication-type)」プロパティを参照してください。
+ ほとんどの CloudFormation リソースとは異なり、`AWS::CloudFormation::Authentication` プロパティ名には小文字キャメル形式が使用されます。

### JSON
<a name="aws-resource-cloudformation-authentication-syntax.json"></a>

```
{
  "AWS::CloudFormation::Authentication" {
    "{{String}}" : {
      "accessKeyId" : {{String}},
      "buckets" : [ {{String, ...}} ],
      "password" : {{String}},
      "secretKey" : {{String}},
      "type" : {{String}},
      "uris" : [ {{String, ...}} ],
      "username" : {{String}},
      "roleName" : {{String}}
    }
  }
}
```

### YAML
<a name="aws-resource-cloudformation-authentication-syntax.yaml"></a>

```
AWS::CloudFormation::Authentication
{{String}}:
  accessKeyId: {{String}}
  buckets:
    - {{String}}
  password: {{String}}
  secretKey: {{String}}
  type: {{String}}
  uris:
    - {{String}}
  username: {{String}}
  roleName: {{String}}
```

## プロパティ
<a name="w2aac19c23c15c19"></a>

`accessKeyId`  <a name="cfn-cloudformation-authentication-accesskeyid"></a>
S3 認証のためのアクセスキー ID を指定します。  
*必須:* 条件的。`type` プロパティが `S3` に設定されている場合にのみ指定できます。  
タイプ: 文字列

`buckets`  <a name="cfn-cloudformation-authentication-buckets"></a>
S3 認証情報に関連付ける Amazon S3 バケットのコンマ区切りのリスト。  
*必須:* 条件的。`type` プロパティが `S3` に設定されている場合にのみ指定できます。  
*タイプ*: 文字列値のリスト

`password`  <a name="cfn-cloudformation-authentication-password"></a>
基本認証のためのパスワードを指定します。  
*必須:* 条件的。type プロパティが `basic` に設定されている場合にのみ指定できます。  
タイプ: 文字列

`secretKey`  <a name="cfn-cloudformation-authentication-secretkey"></a>
S3 認証のためのシークレットキーを指定します。  
必須: 条件的。`type` プロパティが `S3` に設定されている場合にのみ指定できます。  
*タイプ*: 文字列

`type`  <a name="cfn-cloudformation-authentication-type"></a>
認証スキームでユーザー名とパスワード (基本) またはアクセスキー ID とシークレットキー (S3) のどちらを使用するかを指定します。  
`basic` を指定した場合は、`username`、`password` および `uris` の各プロパティを指定します。  
`S3` を指定した場合は、`accessKeyId`、`secretKey`、および `buckets` (オプション) の各プロパティを指定します。  
*必須:* はい  
*有効な値*: `basic` \| `S3`

`uris`  <a name="cfn-cloudformation-authentication-uris"></a>
基本認証情報に関連付ける URI のコンマ区切りのリスト。認可は、指定された URI と、すべてのより限定された URI に適用されます。たとえば、`http://www.example.com` と指定した場合、認可は `http://www.example.com/test` にも適用されます。  
*必須:* 条件的。`type` プロパティが `basic` に設定されている場合にのみ指定できます。  
*タイプ*: 文字列値のリスト

`username`  <a name="cfn-cloudformation-authentication-username"></a>
基本認証のためのユーザー名を指定します。  
*必須:* 条件的。type プロパティが `basic` に設定されている場合にのみ指定できます。  
タイプ: 文字列

`roleName`  <a name="cfn-cloudformation-authentication-rolename"></a>
ロールベースの認証のためのロールを記述します。  
このロールは、EC2 インスタンスにアタッチされているインスタンスプロファイルに含まれている必要があります。インスタンスプロファイルに含めることができる IAM ロールは 1 つのみです。
*必須:* 条件的。`type` プロパティが `S3` に設定されている場合にのみ指定できます。  
*型*:文字列

## 例
<a name="aws-resource-authentication-examples"></a>

**Topics**
+ [EC2 ウェブサーバー認証](#aws-resource-cloudformation-authentication-example1)
+ [基本認証と S3 認証の指定](#aws-resource-cloudformation-authentication-example2)
+ [IAM ロール](#aws-resource-cloudformation-authentication-example3)

### EC2 ウェブサーバー認証
<a name="aws-resource-cloudformation-authentication-example1"></a>

このテンプレートスニペットでは、EC2 インスタンス内のプライベート S3 バケットからファイルを取得する方法を示します。認証情報は `AWS::CloudFormation::Authentication` メタデータに定義され、*files* セクションの `AWS::CloudFormation::Init` メタデータによって参照されます。

#### JSON
<a name="aws-resource-cloudformation-authentication-example1.json"></a>

```
"WebServer": {
   "Type": "AWS::EC2::Instance",
   "DependsOn" : "BucketPolicy",
   "Metadata" : {
      "AWS::CloudFormation::Init" : {
         "config" : {
            "packages" : { "yum" : { "httpd" : [] } },
            "files" : {
               "/var/www/html/index.html" : {
                  "source" : {
                     "Fn::Join" : [
                        "", [ "http://s3.amazonaws.com/", { "Ref" : "BucketName" }, "/index.html" ]
                     ]
                  },
                  "mode"   : "000400",
                  "owner"  : "apache",
                  "group"  : "apache",
                  "authentication" : "S3AccessCreds"
               }
            },
            "services" : {
               "sysvinit" : {
                  "httpd" : { "enabled" : "true", "ensureRunning" : "true" }
               }
            }
         }
      },
      "AWS::CloudFormation::Authentication" : {
         "S3AccessCreds" : {
            "type" : "S3",
            "accessKeyId" : { "Ref" : "AccessKeyID" },
            "secretKey" : { "Ref" : "SecretAccessKey" }
         }
      }
   },
   "Properties": {
   {{EC2 Resource Properties ...}}
   }
}
```

#### YAML
<a name="aws-resource-cloudformation-authentication-example1.yaml"></a>

```
WebServer: 
  Type: AWS::EC2::Instance
  DependsOn: BucketPolicy
  Metadata: 
    AWS::CloudFormation::Init: 
      config: 
        packages: 
          yum: 
            httpd: []
        files: 
          /var/www/html/index.html: 
            source: !Join
              - ''
              - - 'http://s3.amazonaws.com/'
                - !Ref BucketName
                - '/index.html'
            mode: '000400'
            owner: apache
            group: apache
            authentication: S3AccessCreds
        services: 
          sysvinit: 
            httpd: 
              enabled: 'true'
              ensureRunning: 'true'
    AWS::CloudFormation::Authentication: 
      S3AccessCreds: 
        type: S3
        accessKeyId: !Ref AccessKeyID
        secretKey: !Ref SecretAccessKey
  Properties: 
  {{EC2 Resource Properties ...}}
```

### 基本認証と S3 認証の指定
<a name="aws-resource-cloudformation-authentication-example2"></a>

次のサンプルテンプレートスニペットには、*basic* 認証タイプと *S3* 認証タイプの両方が含まれています。

#### JSON
<a name="aws-resource-cloudformation-authentication-example2.json"></a>

```
"AWS::CloudFormation::Authentication" : {
   "testBasic" : {
      "type" : "basic",
      "username" : { "Ref" : "UserName" },
      "password" : { "Ref" : "Password" },
      "uris" : [ "example.com/test" ]
   },
   "testS3" : {
      "type" : "S3",
      "accessKeyId" : { "Ref" : "AccessKeyID" },
      "secretKey" : { "Ref" : "SecretAccessKey" },
      "buckets" : [{ "Fn::Sub": "${BucketName}" }]
   }
}
```

#### YAML
<a name="aws-resource-cloudformation-authentication-example2.yaml"></a>

```
AWS::CloudFormation::Authentication: 
  testBasic: 
    type: basic
    username: !Ref UserName
    password: !Ref Password
    uris: 
      - 'example.com/test'
  testS3: 
    type: S3
    accessKeyId: !Ref AccessKeyID
    secretKey: !Ref SecretAccessKey
    buckets: 
      - !Sub ${BucketName}
```

### IAM ロール
<a name="aws-resource-cloudformation-authentication-example3"></a>

次の例に、IAM ロールの使用法を示します。
+ `myRole` は、[AWS::IAM::Role](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-iam-role.html) リソースです。
+ `cfn-init` を実行している Amazon EC2 インスタンスは、インスタンスプロファイルを介して `myRole` に関連付けられます。
+ 例では、`buckets` プロパティを使用して認証を指定しています (Amazon S3 認証と同様)。また、認証を名前で指定することもできます。

#### JSON
<a name="aws-resource-cloudformation-authentication-example3.json"></a>

```
"AWS::CloudFormation::Authentication": {
    "rolebased" : {
        "type": "S3",
        "buckets": [{ "Fn::Sub": "${BucketName}" }],
        "roleName": { "Ref": "myRole" }
    }
}
```

#### YAML
<a name="aws-resource-cloudformation-authentication-example3.yaml"></a>

```
AWS::CloudFormation::Authentication:
  rolebased:
    type: S3
    buckets:
      - !Sub ${BucketName}
    roleName: !Ref myRole
```