Cloudformation: Create array of log ARNs from comma delimited list of log names

Viewed 54

I have parameter LogNames - comma delimited list of log names:

  LogNames:
    Type: String
    Default: >-
      /aws/my-custom-log-1,/aws/my-custom-log-1

I want to use it in the IAM policy definition - Resource field:

Resource:
  <array of allowed log ARNs created from LogNames parameter>

Any idea how to use functions e.g. Split, Join, Sub, ... to generate correct array of log ARNs? Single log ARN have syntax:

- !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${LogName}:*'
1 Answers

Its not possible without a macro or a custom resource. The only way to do it without these, is to hardcode your region and accountid and use combo of Split, Join, Sub:

Parameters:
  LogNames:
    Type: CommaDelimitedList
    Default: >-
      /aws/my-custom-log-1,/aws/my-custom-log-2,/aws/my-custom-log-3

Resource:
          !Split:
            - ","
            - !Sub
                - "arn:aws:logs:us-east-1:234234234234:log-group:${logname}"
                - logname: !Join
                          - ",arn:aws:logs:us-east-1:234234234234:log-group:"
                          - !Ref LogNames
Related