获取无服务器框架在我的 serverless.yml 文件中创建的 API 网关资源的 ARN
Get the ARN for the API gateway resource that the serverless framework creates within my serverless.yml file
如何获取无服务器框架在我的 serverless.yml 文件中创建的 API 网关资源的 ARN?
我想获取 API 网关资源的 ARN,以便我可以在 IAM 策略中使用它在网关上执行基于 IAM 的授权。
API 的整个 ARN 是 form: arn:aws:execute-api:region:account-id:api-id/stage/METHOD_HTTP_VERB/Resource-path
). Using { "Ref" : "ApiGatewayRestApi" }
(link) 在您的 serverless.yml 中为您提供的 apiId。
您可以执行类似下面的操作(请参阅资源部分)将其转换为整个 Arn 以引用 API:
PolicyName: InvokeAPI
PolicyDocument:
Version: "2012-10-17"
Statement:
Effect: "Allow"
Action: "execute-api:Invoke"
Resource:
- Fn::Join:
- "/"
-
- Fn::Join: [":", ["arn:aws:execute-api", {"Ref": "AWS::Region"}, {"Ref":"AWS::AccountId"}, {"Ref": "ApiGatewayRestApi"}]]
- "*"
如何获取无服务器框架在我的 serverless.yml 文件中创建的 API 网关资源的 ARN?
我想获取 API 网关资源的 ARN,以便我可以在 IAM 策略中使用它在网关上执行基于 IAM 的授权。
API 的整个 ARN 是 form: arn:aws:execute-api:region:account-id:api-id/stage/METHOD_HTTP_VERB/Resource-path
). Using { "Ref" : "ApiGatewayRestApi" }
(link) 在您的 serverless.yml 中为您提供的 apiId。
您可以执行类似下面的操作(请参阅资源部分)将其转换为整个 Arn 以引用 API:
PolicyName: InvokeAPI
PolicyDocument:
Version: "2012-10-17"
Statement:
Effect: "Allow"
Action: "execute-api:Invoke"
Resource:
- Fn::Join:
- "/"
-
- Fn::Join: [":", ["arn:aws:execute-api", {"Ref": "AWS::Region"}, {"Ref":"AWS::AccountId"}, {"Ref": "ApiGatewayRestApi"}]]
- "*"