确认IAM策略和API Gateway配置是否正确。在IAM策略中,确保“Effect”为“Deny”,同时在API Gateway资源的“Method Execution”中选择正确的IAM策略。
确认ARN格式是否正确。ARN(Amazon Resource Name)标识AWS中的资源。在IAM策略中使用ARN来确定应用策略的范围。您可以使用AWS IAM Policy Simulator来模拟策略的应用,以验证ARN是否可用。
以下是IAM策略和API Gateway资源定义的示例:
IAM策略:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Action": [ "execute-api:Invoke" ], "Resource": [ "arn:aws:execute-api:us-east-1:account-id:api-id/stage-name/*/http method/resource path" ] } ] }
API Gateway资源:
{ "swagger": "2.0", "info": { "version": "1.0.0", "title": "API Gateway Demo" }, "paths": { "/pets": { "get": { "x-amazon-apigateway-integration": { "uri": "arn:aws:lambda:us-east-1:account-id:function:my-function", "httpMethod": "POST", "type": "aws_proxy" }, "security": [{ "api_key": [] }] } } } }