amazon-web-services - cloudformation中Elasticache集群的引用arn

标签 amazon-web-services redis aws-cloudformation amazon-elasticache aws-policies

我想在云形成模板中引用“即将创建的”Redis ElastiCache 集群的 arn。
这是 ElasticacheCluster 模板(已在 cloudFormation 中测试并工作)

ElasticacheCluster:
Type: AWS::ElastiCache::CacheCluster
Properties:
  AutoMinorVersionUpgrade: 'true'
  Engine: redis
  CacheNodeType: cache.t2.micro
  NumCacheNodes: '1'
  VpcSecurityGroupIds:
  - Fn::GetAtt:
    - ElastiCacheSecurityGroup
    - GroupId
  CacheSubnetGroupName:
    Ref: ElastiCacheSubnetGroup

我删掉了其他工作人员,例如子网组和安全组,因为它在这里也不相关。我应该使用我正在尝试的访问策略向另一个资源授予对集群的访问权限:

AccessPolicies:
    Version: '2012-10-17'
    Statement:
    - Effect: Allow
      Principal:
        AWS: "*"
      Action: es:*
      Resource: !GetAtt ElasticacheCluster.Arn
    - Effect: Allow
      Principal:
        AWS: "*"
      Action: es:*
      Resource: !GetAtt ElasticacheCluster.Arn
      Condition:
        IpAddress:
          aws:SourceIp: 0.0.0.0/0

我看到了这个:

the !GetAtt ElasticacheCluster.Arn for the resource entry

here但在这种情况下似乎不起作用,因为 !GetAtt 返回一组固定的属性,而 ARN 不是其中之一(正如@Anton 在评论中所建议的那样。

我还看到了this other question这可以解决这个问题,但我更喜欢一个不依赖于区域和帐户 ID 之类的非编码解决方案。
问题的解决方案似乎很简单,但我正在努力寻找一个干净的答案。

最佳答案

我从@multiscup的答案和one中获得了灵感。问题中提到。
这种方法远非干净,我正在等待更好的答案,但至少它是有效的。 主要思想是构造 arn 所需的字符串:

arn:aws:elasticache:region:account-id:cluster:resource-name

为此,我使用了一个连接,尝试通过内置的 CloudFormation 函数动态获取元素:

Resource: !Join 
        - ':'
        - - 'arn:aws:elasticache' 
          - !Ref 'AWS::Region'
          - '<your-account-id>'
          - 'cluster'
          - !FindInMap [Elasticache, Redis, cluster-name]

我使用 Map 来定义 Redis 集群,因为我在 CloudFormation 模板的其他点中也使用了相同的值。也许您可能会发现 map 也很有帮助

Mappings: 
  Elasticache: 
    Redis:
      cluster-name: redis-demo

关于amazon-web-services - cloudformation中Elasticache集群的引用arn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71601033/

相关文章:

java - 过期的 Redisson key 在 Redis Cli 中仍然可见

ruby - Redis 命名空间基础知识

android - 更快、更高效地下载图像

amazon-web-services - 数据湖 - S3 和 Databricks

amazon-web-services - NoCredentialProviders : no valid providers in chain error in electron-updater with AWS S3

amazon-web-services - 尝试创建或更新 Route53 A 记录时出现 InvalidInput 错误

redis - 使用 redis 哨兵时,如何使用密码保护主节点和副本节点?

json - Cloudformation,模板验证错误: Invalid template property or properties

amazon-web-services - 使用 Terraform 启动 CloudFormationTemplate

amazon-web-services - AWS Cloudformation - 如何依赖另一个嵌套堆栈中的资源