【问题标题】:Stack policy for custom resources cloudformation自定义资源 cloudformation 的堆栈策略
【发布时间】:2021-03-09 14:55:51
【问题描述】:

我已经定义了这样的 cloudformation 模板:

AWSTemplateFormatVersion: 2010-09-09
Description: Auth stack
Transform: AWS::Serverless-2016-10-31

Parameters:
  DeveloperProviderName:
    Description: Developer provider name
    Type: String

Conditions:
  Never:
    !Equals [ "true", "false" ]

Resources:
  CognitoIdentityPool:
    Type: Custom::CognitoIdentityPool
    Version: '1.0'
    Properties:
      IdentityPoolName: !Sub "${AWS::StackName}-cognito-idp"
      DeveloperProviderName: !Ref DeveloperProviderName
      ServiceToken: !GetAtt CreateIdentityPoolFunction.Arn

.
.
more stuff here for the lambda function etc
.
.

那我想加个栈策略,拒绝replace和delete:

{
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "Update:*",
      "Principal": "*",
      "Resource": "*"
    },
    {
      "Effect": "Deny",
      "Action": [
        "Update:Replace",
        "Update:Delete"
      ],
      "Principal": "*",
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "ResourceType": [
            "Custom::CognitoIdentityPool"
          ]
        }
      }
    }
  ]
}

这就是我设置堆栈策略的方式:

aws cloudformation set-stack-policy \
    --stack-name ${stackName} \
    --stack-policy-body file://${policyPath} 

这是我在设置堆栈策略时遇到的错误:

An error occurred (ValidationError) when calling the SetStackPolicy operation: Error validating stack policy: Unknown resource type 'Custom::CognitoIdentityPool' in statement {}

任何想法如何使用堆栈策略保护这些自定义资源?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-cognito


    【解决方案1】:

    我认为您不能使用自定义资源。 AWS docs

    指定策略适用的the resource type。要指定特定资源的逻辑 ID,请使用 Resource 元素。

    其中“资源类型”是 AWS 提供的资源类型之一。

    【讨论】:

    • 据我所知没有解决办法。
    • @StavrosZavrakas 它的自定义资源,因此您可以对其进行编程以忽略任何删除或更新。但除此之外,我不知道有什么更好的解决方案。
    猜你喜欢
    • 2021-10-12
    • 1970-01-01
    • 2016-06-09
    • 2018-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 2019-08-02
    相关资源
    最近更新 更多