【问题标题】:Integrate Lambda with rest endpoint using aws cli使用 aws cli 将 Lambda 与 REST 端点集成
【发布时间】:2019-06-15 21:00:39
【问题描述】:

我正在尝试使用 aws cli 集成 lambda 和 rest api 网关端点并运行以下命令但出现以下错误

aws apigateway put-integration  --region us-west-2 --rest-api-id 91b73m5i10  --resource-id pjg2ac --http-method GET --type AWS --integration-http-method GET --uri arn:aws:apigateway:us-west-2:lambda:path/apigateway/functions/arn:aws:lambda:us-west-2:xxxxx:function:sendFile_Trips_divyanayan/invocations

调用 PutIntegration 操作时发生错误 (NotFoundException):指定的方法标识符无效

看过这篇相关文章,但没有太大帮助

Create api-gateway lambda integration using aws-cli

【问题讨论】:

标签: amazon-web-services aws-lambda aws-api-gateway aws-cli


【解决方案1】:

错误是不言自明的。您的 ApiGateway 端点很可能在该资源上没有 GET 方法。

请添加相同的内容,然后尝试运行上述命令。

您可能需要为IAM 角色添加--credentials 参数,即ARN,它允许与lambda 函数集成。

还需要将--integration-http-method改为POST(这是apigateway-lambda之间的默认集成方式。

aws apigateway put-integration  --region us-west-2 --rest-api-id 91b73m5i10  --resource-id pjg2ac --http-method GET --type AWS_PROXY --integration-http-method POST --uri arn:aws:apigateway:us-west-2:lambda:path//2015-03-31/functions/arn:aws:lambda:us-west-2:xxxxxxxx:function:sendFile_Trips_divyanayan/invocations --credentials arn:aws:iam::xxxxxxxx:role/lambda-role

此外,凭据中给出的角色在受信任的关系(委托人)中应具有以下特征

    {
        "Version": "2012-10-17",
        "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
            "Service": [
                "apigateway.amazonaws.com",
                "logs.amazonaws.com",
                "lambda.amazonaws.com"
            ]
        },
        "Action": "sts:AssumeRole"
    }
  ]
}

注意:在外部论坛提问时不要暴露 accountId。

【讨论】:

  • 当我尝试从 Web 控制台测试 api 时,由于配置错误,执行失败:API 网关无权承担提供的角色 arn:aws:iam::3xxxxxx:role/lambda_role.Is这涉及到我的帐户的一些访问问题。如果我删除了 put_integration 上的角色,我得到以下错误:由于配置错误,执行失败:Lambda 函数的权限无效
  • 在 IAM 角色中,您需要添加可以担任该角色的服务名称(即 apiGateway)。
  • 是否强制传递凭据?我有一个 lambda 角色,我们有一些最小权限来执行 poc,所以当我使用该角色时,它会给我错误,因为 API Gateway 无权承担提供的角色 arn:aws:iam::3xxxxxx:role/lambda_role
  • 这又是我的命令 .aws apigateway put-integration --region us-west-2 --rest-api-id 0bovdlngz6 --resource-id fuoq79 --http-method GET --type AWS --integration-http-method GET --uri arn:aws:apigateway:us-west-2:lambda:path/greeting/functions/arn:aws:lambda:us-west-2:xxxx:function:helloworld- divyanayan_lambda/invocations .where /greeting 是资源,api 网关名称是 HelloWorld-divyanayan
  • 进入 lambda_role 并在信任关系选项卡中添加 apigateway.amazonaws.com 作为受信任的实体。
猜你喜欢
  • 2017-02-08
  • 2018-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多