AWS::CloudFormation::Authentication - AWS CloudFormation

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

AWS::CloudFormation::Authentication

使用 AWS::CloudFormation::Authentication 資源來指定您使用 AWS::CloudFormation::Init 資源指定之檔案或來源的身分驗證憑證。

若要包含指定的檔案或來源的身份驗證資訊AWS::CloudFormation::Init,請使用uris屬性 (如果來源是一個來源)URI;如果來源是 Amazon S3 儲存貯體,請使用該buckets屬性。如需檔案的詳細資訊,請參閱檔案。如需來源的詳細資訊,請參閱 來源

您也可以在 AWS::CloudFormation::Init 資源中直接指定檔案的身分驗證資訊。資源的 files 金鑰包含名為 authentication 的屬性。您可以使用 authentication 屬性將在 資源中定義的身分驗證資訊,直接與檔案建立關聯。AWS::CloudFormation::Authentication

對於檔案,請依下列順序 AWS CloudFormation 尋找驗證資訊:

  1. authentication AWS::CloudFormation::Init 金鑰的 files 屬性。

  2. uris 資源的 bucketsAWS::CloudFormation::Authentication 屬性。

對於來源,請在資源的 uris or buckets 屬性中 CloudFormation 尋找驗證AWS::CloudFormation::Authentication資訊。

語法

若要在 CloudFormation 範本中宣告此實體,請使用下列語法:

使用 AWS::CloudFormation::Authentication 類型時,您應該清楚下列事項:

  • 與大多數 CloudFormation 資源不同,此AWS::CloudFormation::Authentication類型不包含名為 Properties 的區塊,而是包含使用者命名區塊的清單,每個區塊都包含自己的驗證屬性。

    並非所有屬性都屬於每一種身分驗證類型。請參閱 type 屬性以取得詳細資訊。

  • 與大多數 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

指定身分驗證機制是否使用使用者名稱及密碼 ("basic") 或存取金鑰 ID 及秘密金鑰 ("S3")。

若您指定 "basic",請指定 usernamepassworduris 屬性。

若您指定 "S3",請指定 accessKeyIdsecretKeybuckets (選擇性) 屬性。

必要:是

有效值basic | S3

uris

URIs要與基本認證證明資料相關聯的逗號分隔清單。該授權適用於指定的URIs和更具體的URI。例如,若您指定 http://www.example.com,授權也會套用至 http://www.example.com/test

必要:有條件限制。只有在 type 屬性設為 "basic" 時,才能指定此項目。

類型:字串值清單

username

指定基本身分驗證的使用者名稱。

必要:有條件限制。只有在 type 屬性設為 "basic" 時,才能指定此項目。

類型:字串

roleName

描述角色式身分驗證的角色。

重要

此角色必須包含在連接至執行個體的執EC2行個體設定檔中。執行個體設定檔只能包含一個 IAM 角色。

必要:有條件限制。只有在 type 屬性設為 "S3" 時,才能指定此項目。

類型:字串

範例

注意

與大多數的資源不同,AWS::CloudFormation::Authentication 類型會定義一組使用者命名的區塊清單,其中每一項都包含使用小寫連字 (camel case) 命名的身分驗證屬性。

EC2網頁伺服器驗證

此範本程式碼片段顯示如何從執行個體內的私有 S3 儲存貯EC2體取得檔案。用於身分驗證的登入資料是在 AWS::CloudFormation::Authentication 資源中定義,而且 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" : "CfnKeys" }, "secretKey" : { "Fn::GetAtt": [ "CfnKeys", "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: 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: "CfnKeys" secretKey: Fn::GetAtt: - "CfnKeys" - "SecretAccessKey" Properties: EC2 Resource Properties ...

指定基本和 S3 身分驗證

以下範例範本程式碼片段同時包含了基本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" : "SecretAccessKeyID" }, "buckets" : [ "amzn-s3-demo-bucket1" ] } }

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: "SecretAccessKeyID" buckets: - "myawsbucket"

IAM 角色

下面的例子演示了如何使用 IAM 角色:

  • myRole:AWS:IAM: 角色資源。

  • 執行的 Amazon EC2 執行個體與執行cfn-initmyRole體設定檔相關聯。

  • 範例會使用 buckets 屬性指定身分驗證,與 Amazon S3 身分驗證中的情況相同。您也可以使用名稱指定身分驗證。

JSON

"AWS::CloudFormation::Authentication": { "rolebased" : { "type": "S3", "buckets": [ "myBucket" ], "roleName": { "Ref": "myRole" } } }

YAML

AWS::CloudFormation::Authentication: rolebased: type: "S3" buckets: - "myBucket" roleName: Ref: "myRole"