SNR
SNR

Reputation: 510

How to create list of resource ARNS using a CommaDelimitedList parameter?

I am trying to create a Cloudwatch event rule which will use multiple Codepipelines as source and triggers target.

Parameters:
  SourcePipeline:
    Description: Name of Source codepipeline
    Type: CommaDelimitedList
    Default: 'test3, test4'

Resources:
  PipelineTrigger:
    Type: 'AWS::Events::Rule'
    Properties:
      EventPattern:
        source:
          - aws.codepipeline
        resources: !Split 
          - ','
          - !Sub 
            - 'arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${pipeline}'
            - pipeline: !Join 
                - ',arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:'
                - !Ref SourcePipeline

Expecting resources as below:

  "resources": ["arn:aws:codepipeline:us-east-1:123:test3","arn:aws:codepipeline:us-east-1:123:test4"],

Any idea how to pass the list of names as a parameter?

@FYI Reference i am following Using Lists of ARNs

Upvotes: 1

Views: 545

Answers (1)

Marcin
Marcin

Reputation: 238477

First, it should be !Ref SourcePipelines. Second you forgot about comma. you can't do this the way you want. This is because, the first parameter to join must be literal string, not any CloudFormation expression or function. So you have to hardcode your account id and region:

        resources: !Split
          - ','
          - !Sub
            - 'arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${pipeline}'
            - pipeline: !Join
                - ',arn:aws:codepipeline:us-east-1:12312321:'
                - !Ref SourcePipelines

Upvotes: 2

Related Questions