リソースポリシーの例 - AWS Serverless Application Model

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

リソースポリシーの例

API へのアクセスは、 AWS SAM テンプレート内でリソースポリシーをアタッチすることによって制御できます。これを実行するには、ApiAuth データ型を使用します。

以下はプライベート API AWS SAM のテンプレートの例です。プライベート API にはデプロイするリソースポリシーが必要です。

AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: MyPrivateApi: Type: AWS::Serverless::Api Properties: StageName: Prod EndpointConfiguration: PRIVATE # Creates a private API. Resource policies are required for all private APIs. Auth: ResourcePolicy: CustomStatements: { Effect: 'Allow', Action: 'execute-api:Invoke', Resource: ['execute-api:/*/*/*'], Principal: '*' } MyFunction: Type: 'AWS::Serverless::Function' Properties: InlineCode: | def handler(event, context): return {'body': 'Hello World!', 'statusCode': 200} Handler: index.handler Runtime: python3.10 Events: AddItem: Type: Api Properties: RestApiId: Ref: MyPrivateApi Path: / Method: get

リソースポリシーの詳細については、API Gateway デベロッパーガイドの「API Gateway リソースポリシーを使用して API へのアクセスを制御する」を参照してください。プライベート API の詳細については、『API ゲートウェイ開発者ガイド』の「Amazon API Gateway でのプライベート API の作成」を参照してください。