【问题标题】:How to generate an AWS String condition using cloudformation如何使用 cloudformation 生成 AWS 字符串条件
【发布时间】:2022-08-14 16:07:03
【问题描述】:

我有以下代码,但无法使用 StringEquals 获取结尾部分以打印运行 cloudformation 的正确值。

Parameters:
  OpenIDClientIdList:
    Type: String
    Description: Open ID client ID 
    Default: urn:dev.aws.services.xxxxx.com

  OpenIDURL:
    Type: String
    Description: Open ID URL
    Default: \"sts.windows.net/dddddd-rr444-ssss-94c3-7484898492d/\"

Resources:
  OpenIDCAssumeReadOnlyRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: OpenIDCAssumeReadOnlyRole
      ManagedPolicyArns: [arn:aws:iam::aws:policy/ReadOnlyAccess]
      AssumeRolePolicyDocument:
        Statement:
        - Effect: Allow
          Principal:
            Federated: !Sub arn:aws:iam::${AWS::AccountId}:oidc-provider/${OpenIDURL}
          Action: sts:AssumeRoleWithWebIdentity
          Condition:
            StringEquals: !Sub
              - \'\'
              - - \'${OpenIDURL}:aud:\'
                - \'${OpenIDClientIdList}\'

预期条件字符串值

         \"Action\": \"sts:AssumeRoleWithWebIdentity\",
            \"Condition\": {
                \"StringEquals\": {
                    \"sts.windows.net/dddddd-rr444-ssss-94c3-7484898492d/:aud\": \"urn:dev.aws.services.xxxxx.com\"
                }
            }
  • 当前不正确的值是多少?
  • 我的回答对你有用吗?

标签: amazon-web-services amazon-cloudformation


【解决方案1】:

您没有正确使用!Sub。条件如下所示:

Condition:
  StringEquals: 
    Fn::Base64: !Sub
    - |
      "${OPENIDURL}:aud": "${OPENIDCLIENTIDLIST}"
    - OPENIDURL: !Ref OpenIDURL
      OPENIDCLIENTIDLIST: !Ref OpenIDClientIdList

【讨论】:

  • 谢谢@Paolo,我尝试了 aboce 建议但得到了Template error: One or more Fn::Sub intrinsic functions don't specify expected arguments. Specify a string as first argument, and an optional second argument to specify a mapping of values to replace in the string
  • @manthaRIBBS 我已经解决了我的答案,你能再试一次吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-22
  • 2011-01-01
相关资源
最近更新 更多