AWS::CloudFormation::Authentication
リソースを使用して、AWS::CloudFormation::Init リソースで指定したファイルまたはソースの認証情報を指定します。
AWS::CloudFormation::Init
で指定したソースまたはファイルの認証情報を含めるには、ソースが URI の場合は uris
プロパティを使用し、ソースが Amazon S3 バケットの場合は buckets
プロパティを使用します。files の詳細については、「ファイル」を参照してください。sources の詳細については、「[Sources] (出典)」を参照してください。
ファイルの認証情報は、AWS::CloudFormation::Init
リソースに直接指定することもできます。リソースの files キーには、authentication
というプロパティが含まれます。authentication
プロパティを使用すると、 リソースに定義された認証情報をファイルに直接関連付けることができます。AWS::CloudFormation::Authentication
ファイルの場合、AWS CloudFormation は次の順序で認証情報を検索します。
-
authentication
AWS::CloudFormation::Init
キーのfiles
プロパティ。 -
uris
リソースのbuckets
プロパティまたはAWS::CloudFormation::Authentication
プロパティ。
ソースの場合、CloudFormation は、AWS::CloudFormation::Authentication
リソースの uris
プロパティまたは buckets
プロパティ内で認証情報を検索します。
構文
CloudFormation テンプレートでこのエンティティを宣言するには、次の構文を使用します。
AWS::CloudFormation::Authentication
タイプを使用するときは、以下の考慮事項に注意してください。
-
ほとんどの CloudFormation リソースとは異なり、
AWS::CloudFormation::Authentication
タイプには、[Properties] (プロパティ) という名前のブロックが含まれません。その代わりに、ユーザーによって名前が付けられたブロックのリストが含まれます。各ブロックには、それぞれ独自の認証プロパティが含まれます。すべてのプロパティが各認証タイプと関係があるわけではありません。詳細については、「タイプ」を参照してください。
-
ほとんどの CloudFormation リソースとは異なり、プロパティ名にはローワーキャメルケースが使用されます。
JSON
{
"Type" : "AWS::CloudFormation::Authentication" {
"String
" : {
"accessKeyId" : String
,
"buckets" : [ String, ...
],
"password" : String
,
"secretKey" : String
,
"type" : String
,
"uris" : [ String, ...
],
"username" : String
,
"roleName" : String
}
}
}
YAML
Type: AWS::CloudFormation::Authentication
String
:
accessKeyId: String
buckets:
- String
password: String
secretKey: String
type: String
uris:
- String
username: String
roleName: String
プロパティ
accessKeyId
-
S3 認証のためのアクセスキー ID を指定します。
必須: 条件的。
type
プロパティがS3
に設定されている場合にのみ指定できます。タイプ: 文字列
buckets
-
S3 認証情報に関連付ける Amazon S3 バケットのコンマ区切りのリスト。
必須: 条件的。
type
プロパティがS3
に設定されている場合にのみ指定できます。タイプ: 文字列値のリスト
password
-
基本認証のためのパスワードを指定します。
必須: 条件的。type プロパティが
basic
に設定されている場合にのみ指定できます。タイプ: 文字列
secretKey
-
S3 認証のためのシークレットキーを指定します。
必須: 条件的。
type
プロパティがS3
に設定されている場合にのみ指定できます。型: 文字列
type
-
認証スキームでユーザー名とパスワード (基本) またはアクセスキー ID とシークレットキー (S3) のどちらを使用するかを指定します。
basic
を指定した場合は、username
、password
およびuris
の各プロパティを指定します。S3
を指定した場合は、accessKeyId
、secretKey
、およびbuckets
(オプション) の各プロパティを指定します。必須: はい
有効な値:
basic
|S3
uris
-
基本認証情報に関連付ける URI のコンマ区切りのリスト。認可は、指定された URI と、すべてのより限定された URI に適用されます。たとえば、
http://www.example.com
と指定した場合、認可はhttp://www.example.com/test
にも適用されます。必須: 条件的。
type
プロパティがbasic
に設定されている場合にのみ指定できます。タイプ: 文字列値のリスト
username
-
基本認証のためのユーザー名を指定します。
必須: 条件的。type プロパティが
basic
に設定されている場合にのみ指定できます。タイプ: 文字列
roleName
-
ロールベースの認証のためのロールを記述します。
重要
このロールは、EC2 インスタンスにアタッチされているインスタンスプロファイルに含まれている必要があります。インスタンスプロファイルに含めることができる IAM ロールは 1 つのみです。
必須: 条件的。
type
プロパティがS3
に設定されている場合にのみ指定できます。タイプ: 文字列。
例
注記
ほとんどのリソースとは異なり、AWS::CloudFormation::Authentication
タイプには、ユーザーによって名前が付けられたブロックのリストが定義されます。各ブロックには、小文字キャメル形式で名前が付けられた認証プロパティが含まれます。
EC2 ウェブサーバー認証
このテンプレートスニペットでは、EC2 インスタンス内のプライベート S3 バケットからファイルを取得する方法を示します。ファイルの認証情報は AWS::CloudFormation::Authentication
リソースに定義され、files セクションの AWS::CloudFormation::Init
リソースによって参照されます。
JSON
"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
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 認証の指定
次のサンプルテンプレートスニペットには、basic 認証タイプと S3 認証タイプの両方が含まれています。
JSON
"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
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 ロール
次の例に、IAM ロールの使用法を示します。
-
myRole
は、AWS::IAM::Role リソースです。 -
cfn-init
を実行している Amazon EC2 インスタンスは、インスタンスプロファイルを介してmyRole
に関連付けられます。 -
例では、
buckets
プロパティを使用して認証を指定しています (Amazon S3 認証と同様)。また、認証を名前で指定することもできます。
JSON
"AWS::CloudFormation::Authentication": {
"rolebased" : {
"type": "S3",
"buckets": [{ "Fn::Sub": "${BucketName}" }],
"roleName": { "Ref": "myRole" }
}
}
YAML
AWS::CloudFormation::Authentication:
rolebased:
type: S3
buckets:
- !Sub ${BucketName}
roleName: !Ref myRole