AWS::ApiGateway::ApiKey
AWS::ApiGateway::ApiKey
リソースは、API キーを必要とする API Gateway Method
リソースを実行しているクライアントに配信できる固有キーを作成します。クライアントがどの API キーを使用するべきかを指定するには、キーを必要とするメソッドを含む
RestApi
および Stage
リソースに API キーをマッピングします。
構文
AWS CloudFormation テンプレートでこのエンティティを宣言するには、次の構文を使用します。
JSON
{ "Type" : "AWS::ApiGateway::ApiKey", "Properties" : { "CustomerId" :
String
, "Description" :String
, "Enabled" :Boolean
, "GenerateDistinctId" :Boolean
, "Name" :String
, "StageKeys" :[ StageKey, ... ]
, "Tags" :[ Tag, ... ]
, "Value" :String
} }
YAML
Type: AWS::ApiGateway::ApiKey Properties: CustomerId:
String
Description:String
Enabled:Boolean
GenerateDistinctId:Boolean
Name:String
StageKeys:- StageKey
Tags:- Tag
Value:String
プロパティ
CustomerId
-
AWS SaaS Marketplace との統合時に使用する AWS Marketplace 顧客 ID。
必須: いいえ
タイプ: 文字列
Update requires: No interruption
Description
-
API キーの説明。
必須: いいえ
タイプ: 文字列
Update requires: No interruption
Enabled
-
API キーがクライアントで使用できるかどうかを示します。
必須: いいえ
タイプ: ブール値
Update requires: No interruption
GenerateDistinctId
-
キー識別子が作成された API キーの値と異なるかどうかを指定します。このパラメータは廃止されるため、使用しないでください。
必須: いいえ
タイプ: ブール値
Update requires: Replacement
Name
-
API キーの名前。名前を指定しない場合、AWS CloudFormation は一意の物理 ID を生成し、その ID を API キー名として使用します。詳細については、Name タイプを参照してください。
重要 名前を指定すると、このリソースの置換が必要な更新はできません。中断が不要であるか、一定の中断が必要な更新であれば、行うことができます。リソースを置き換える必要がある場合は、新しい名前を指定します。
必須: いいえ
タイプ: 文字列
Update requires: Replacement
StageKeys
-
この API キーに関連付けられるステージのリスト。
必須: いいえ
タイプ: StageKey のリスト
Update requires: No interruption
Tags
-
API キーに関連付ける任意のタグの配列(キーと値のペア)。
必須: いいえ
タイプ: Tag のリスト
Update requires: No interruption
Value
-
API キーの値。20 文字以上にする必要があります。
必須: いいえ
タイプ: 文字列
Update requires: Replacement
戻り値
参照番号
m2m1k7sybf
など、API キー ID このリソースの論理 ID を組み込みの Ref
関数に渡すと、Ref
は次を返します: 。
For more information about using the Ref
function, see Ref.
例
API キー
次の例では、API キーを作成し、Test
デプロイメントの TestAPIDeployment
ステージに関連付けます。API キーの前に AWS CloudFormation によってステージとデプロイメントが作成されるように (同じテンプレート内のどこかで宣言します)、例ではデプロイメントとステージに対する依存関係の明示を追加しています。この依存関係がないと、AWS
CloudFormation で先に API キーが作成され、デプロイメントとステージが存在しないために関連付けに失敗する可能性があります。
JSON
{ "ApiKey": { "Type": "AWS::ApiGateway::ApiKey", "DependsOn": [ "TestAPIDeployment", "Test" ], "Properties": { "Name": "TestApiKey", "Description": "CloudFormation API Key V1", "Enabled": "true", "StageKeys": [ { "RestApiId": { "Ref": "RestApi" }, "StageName": "Test" } ] } } }
YAML
ApiKey: Type: 'AWS::ApiGateway::ApiKey' DependsOn: - TestAPIDeployment - Test Properties: Name: TestApiKey Description: CloudFormation API Key V1 Enabled: 'true' StageKeys: - RestApiId: !Ref RestApi StageName: Test
カスタマー ID
次の例では、API キーを作成し、顧客 ID と、個別の ID を作成するかどうかを指定できるようにします。
JSON
{ "Parameters": { "apiKeyName": { "Type": "String" }, "customerId": { "Type": "String" }, "generateDistinctId": { "Type": "String" } }, "Resources": { "ApiKey": { "Type": "AWS::ApiGateway::ApiKey", "Properties": { "CustomerId": { "Ref": "customerId" }, "GenerateDistinctId": { "Ref": "generateDistinctId" }, "Name": { "Ref": "apiKeyName" } } } } }
YAML
Parameters: apiKeyName: Type: String customerId: Type: String generateDistinctId: Type: String Resources: ApiKey: Type: AWS::ApiGateway::ApiKey Properties: CustomerId: !Ref customerId GenerateDistinctId: !Ref generateDistinctId Name: !Ref apiKeyName
以下の資料も参照してください。
-
Amazon API Gateway REST API リファレンスの「apikey:create」