首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ARN作为云形成堆栈中的一个参数

ARN作为云形成堆栈中的一个参数
EN

Stack Overflow用户
提问于 2022-02-07 15:23:48
回答 1查看 1.1K关注 0票数 0

我想使用ARN作为cloudformation EventRuleRegion1 - Target以及EventBridgeIAMrole的参数输入,但是它不能工作。当我用参考函数调用时

原始ARN

代码语言:javascript
复制
arn:aws:events:ap-southeast-2:123456789123:event-bus/central-eventbus-sydney

当我在代码中直接给出arn时,它可以正常工作。

代码

代码语言:javascript
复制
AWSTemplateFormatVersion: 2010-09-09

Parameters:
  EventBridgeName:
    Description: Enter the Event Bridge Name
    Type: String
    Default: ec2-lifecycle-events
    
  EventBusName:
    Description: Enter the Central Event Bus Name
    Type: String
    Default: central-eventbus-sydney
    
  EventBusArn:
    Description: Enter the ARN of Central Event Bus
    Type: String
    Default: arn:aws:events:ap-southeast-2:123456789123:event-bus/central-eventbus-sydney
    
  Monitoringaccount:
    Description: Enter the Monitoring AWS account number
    Type: String
    Default: 123456789123

Resources:
    EventRuleRegion1:
        Type: AWS::Events::Rule
        Properties: 
            Description: Event rule to send events to monitoring account event bus
            EventBusName: default
            EventPattern:
                source:
                    - aws.ec2
                detail-type:
                    - "EC2 Instance State-change Notification"
                detail:
                  state:
                    - "running"
                    - "stopped"
                    - "terminated"
                    
            Name: !Ref EventBridgeName
            State: ENABLED
            Targets: 
                - Arn: >-
                    - !Join [ "", [ !Sub "arn:aws:events:${AWS::Region}:123456789123:event-bus/",!Ref EventBusName ] ]
                  Id: !Ref EventBusName
                  RoleArn: !GetAtt
                    - EventBridgeIAMrole
                    - Arn      
                  
    
    
    EventBridgeIAMrole:
        Type: 'AWS::IAM::Role'
        Properties:
            AssumeRolePolicyDocument:
                Version: 2012-10-17
                Statement:
                    - Effect: Allow
                      Principal:
                        Service: !Sub events.amazonaws.com
                      Action: 'sts:AssumeRole'
            Path: /
            Policies:
                - PolicyName: PutEventsDestinationBus
                  PolicyDocument:
                    Version: 2012-10-17
                    Statement:
                        - Effect: Allow
                          Action:
                            - 'events:PutEvents'
                          Resource:
                            - >-
                              - !Join [ "", [ !Sub "arn:aws:events:${AWS::Region}:123456789123:event-bus/",!Ref EventBusName ] ]

错误

代码语言:javascript
复制
Parameter - !Join [ "", [ !Sub "arn:aws:events:${AWS::Region}:123456789123:event-bus/",!Ref EventBusName ] ] is not valid. Reason: Provided Arn is not in correct format. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: 0d52a1d6-095e-44f7-9455-b7481dc4fb8d; Proxy: null)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-08 06:08:36

>-的使用将导致文本字符串,而不是计算您的CFN函数(join,ref)。它应该是:

代码语言:javascript
复制
            Targets: 
                - Arn: !Join [ "", [ !Sub "arn:aws:events:${AWS::Region}:123456789123:event-bus/",!Ref EventBusName ] ]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71021027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档