使用IAM角色auth类型从步骤函数中调用AWS API网关

发布于 2025-02-09 05:09:44 字数 1426 浏览 2 评论 0原文

我有使用情况,必须在其他AWS帐户中调用API GATWAY REST端点,他们给了我一个可以假设的角色,

我正在考虑两个选项:

  1. 生成Lambda的请求,并调用API
  2. 使用步骤函数以调用API

Q1。我个人认为选项2更好,但是您对第二

季度有何看法。我很难从步骤函数调用剩余端点以下是我的步骤函数定义

{
  "Comment": "A description of my state machine",
  "StartAt": "API Gateway Invoke",
  "States": {
    "API Gateway Invoke": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "endpoint",
        "Method": "GET",
        "Path": "path",
        "AuthType": "IAM_ROLE"
      },
      "End": true
    }
  }
}

IAM角色信任关系

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

扮演角色

{
    "Version": "2012-10-17",
    "Statement": {
        "Effect": "Allow",
        "Action": "sts:AssumeRole",
        "Resource": "role_arn"
    }
}

策略在执行步骤函数时,我会在我获得此错误响应时

{
  "resourceType": "apigateway",
  "resource": "invoke",
  "error": "ApiGateway.403",
  "cause": {
    "Message": "User:rolearn/hUAiLwbfPOsSKqarBDcdelSpeGIbyiZA is not authorized to access this resource"
  }
}

,我尝试将完整的执行权限授予步骤函数,但是这无济于事 我会受到任何帮助,将不胜感激

I have use case where I have to invoke the api gatway rest endpoint in other aws account, they have given me a role to assume,

I am thinking of two options:

  1. generate the request from the lambda and call the api
  2. use step function to invoke the api

Q1. I personally think option 2 is better but what are your view on this

Q2. I have trouble invoking the rest endpoint from the step function here is my step function definition

{
  "Comment": "A description of my state machine",
  "StartAt": "API Gateway Invoke",
  "States": {
    "API Gateway Invoke": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "endpoint",
        "Method": "GET",
        "Path": "path",
        "AuthType": "IAM_ROLE"
      },
      "End": true
    }
  }
}

IAM role trust relationships

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

Policy to assume role

{
    "Version": "2012-10-17",
    "Statement": {
        "Effect": "Allow",
        "Action": "sts:AssumeRole",
        "Resource": "role_arn"
    }
}

when I execute the step function I get this error response

{
  "resourceType": "apigateway",
  "resource": "invoke",
  "error": "ApiGateway.403",
  "cause": {
    "Message": "User:rolearn/hUAiLwbfPOsSKqarBDcdelSpeGIbyiZA is not authorized to access this resource"
  }
}

I have tried giving the full execution invoke permission to the step function but it didn't help
I am stuck any help would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水晶透心 2025-02-16 05:09:45

当前,没有资源策略的步骤功能和API网关之间的跨帐户集成。

我的猜测是,步骤功能无法担任角色。

Currently step function doesn't support cross account integration between step function and API gateway without resource policy.

My guess is the step function is failing to assume the role.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文