简体   繁体   English

从 AWS Lambda function 调用授权的 Api 网关端点

[英]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谢谢

Did you check if the API gateway is configured with auth key?您是否检查过 API 网关是否配置了身份验证密钥?

if yes, your application should pass it through the header with the key x-api-key如果是,您的应用程序应使用密钥x-api-key通过 header 传递它

API Endpoint with Auth API-Key looks like this: API Endpoint with Auth API-Key 如下所示:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从执行角色有权这样做的 AWS Lambda 调用 AWS_IAM 授权的 API 网关终端节点? - How do I call an AWS_IAM authorized API Gateway endpoint from AWS Lambda who's execution role has permission to do so? 如何使用 AWS Websocket API Gateway Lambda 端点回调函数 - How to use AWS Websocket API Gateway Lambda endpoint callback function 从 API Gateway 获取 terraform 中 AWS lambda 的端点 - Get endpoint from API Gateway for an AWS lambda in terraform 使用 Lambda 和 API 网关调用 Sagemaker 端点时出错 - Error in Call to Sagemaker Endpoint with Lambda and API Gateway 是否可以使用AWS API为Lambda函数设置AWS API Gateway端点? - Is it possible to set up an AWS API Gateway endpoint for a Lambda function, using the AWS API? aws api 网关和 lambda:多个端点/功能与单个端点 - aws api gateway & lambda: multiple endpoint/functions vs single endpoint 从 Lambda 调用 API 网关 - Call API Gateway from Lambda 将查询字符串从 AWS API 网关导入 Lambda Python Z86408593C34AF77FDD1Z60DF932F8B52 - Import Query String from AWS API Gateway into Lambda Python Function AWS Gateway永远需要调用lambda函数 - AWS Gateway takes forever to call the lambda function aws lambda如何知道从API网关调用它的端点? - How can an aws lambda know what endpoint called it from API Gateway?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM