[英]Call Authorized Api Gateway endpoint from AWS Lambda function
I'm trying to define a Lambda function that call authenticated endpoint of API Gateway ( authorizationType: AWS_IAM
).我正在尝试定义一个 Lambda function 调用 API 网关(
authorizationType: AWS_IAM
)的经过身份验证的端点。 I've already create the policy:我已经创建了策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"execute-api:Invoke",
"execute-api:InvalidateCache"
],
"Resource": "arn:aws:execute-api:*:<account_id>:*/*/*/*"
}
]
}
And attach the policy to lambda.并将策略附加到 lambda。 But the response from endpoint called is already 403 (forbidden).
但是来自被调用端点的响应已经是 403(禁止)。 I think i have to add some authorization headers to request.
我想我必须添加一些授权标头来请求。 This is the example lambda code (ruby):
这是示例 lambda 代码(红宝石):
require 'httparty'
require 'json'
API_GATEWAY_URL = ENV["API_GATEWAY_URL"]
def lambda_handler(event:, context:)
env = event&.dig("env")
endpoint = event&.dig("enpoint")
complete_url = "https://#{env}.#{API_GATEWAY_URL}/#{endpoint}"
response = HTTParty.get(complete_url)
p response.code
p response.body
end
Does anyone know how i can proceed?有谁知道我可以如何进行? thanks
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.