【问题标题】:CodePipeline Deploying SAM Template Error With Added ActionCodePipeline 部署 SAM 模板错误并添加了操作
【发布时间】:2021-06-03 17:52:12
【问题描述】:

我有一个 SAM 模板,其中包含创建 lambda 函数和 api 网关的资源。该模板与 lambda 函数和 buildspec.yaml 文件的代码一起保存。当我在没有 api 网关资源的情况下通过 codepipeline 运行代码时,SAM 模板被转换然后成功部署。当我包含创建 api 网关所需的资源时,我在创建时出现以下错误:

AccessDenied. User doesn't have permission to call apigateway:GetResources

当我查看附加到 cloudformation 角色的策略时,我有以下信息:

Actions:
  - apigateway:DELETE
  - apigateway:GetResources
  - apigateway:GetRestApis
  - apigateway:POST
Effect: Allow
Resource: !Sub "arn:${AWS::Partition}:apigateway:*::/*"

该操作已定义apigateway:GetResources,但它仍然失败。当我允许所有 api 网关操作时,codepipelinecloudformation 成功部署了模板。那就是如果我有以下声明:

Actions:
  - apigateway:*
Effect: Allow
Resource: !Sub "arn:${AWS::Partition}:apigateway:*::/*"

问题:是否可以让codepipelinecloudformation 创建一个api 网关而不提供catchall(*) api 网关操作?

【问题讨论】:

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


    【解决方案1】:

    API 网关 IAM 策略中没有此类操作,例如:

      - apigateway:GetResources
      - apigateway:GetRestApis
    

    API 网关权限的form 为:

    apigateway:HTTP_VERB
    

    所以你可能需要GET:

    Actions:
      - apigateway:DELETE
      - apigateway:GET
      - apigateway:POST
    

    【讨论】:

    • 我在 IAM 中也注意到了这一点,但我认为我可能忽略了一些东西。有什么方法可以添加这些操作,让 cloudformation 拥有最少的权限来创建和部署基于 SAM 模板的 api 网关?
    • @Lukasz 您可以限制特定资源,而不是使用通配符。但我不认为你可以有比 GET、POST 更渐进的动作......
    猜你喜欢
    • 2020-10-21
    • 2021-04-02
    • 1970-01-01
    • 2017-10-04
    • 2018-03-25
    • 2022-01-14
    • 2018-02-18
    • 2020-11-24
    • 1970-01-01
    相关资源
    最近更新 更多