Consecutive - in a YAML file

Viewed 38

While going through serverless basic setup, I came across a YAML file that has two consecutive - in the definition. Following is the YAML

# serverless.yml
service: myService
provider:
  name: aws
  iam:
    role:
      statements:
        - Effect: 'Allow'
          Action:
            - 's3:ListBucket'
          # You can put CloudFormation syntax in here.  No one will judge you.
          # Remember, this all gets translated to CloudFormation.
          Resource: { 'Fn::Join': ['', ['arn:aws:s3:::', { 'Ref': 'ServerlessDeploymentBucket' }]] }
        - Effect: 'Allow'
          Action:
            - 's3:PutObject'
          Resource:
            Fn::Join:
              - ''
              - - 'arn:aws:s3:::'
                - 'Ref': 'ServerlessDeploymentBucket'
                - '/*'

functions:
  functionOne:
    handler: handler.functionOne
    memorySize: 512

Here we can see that in - - 'arn:aws:s3:::' there are two consecutive -. Can somebody help me understand what does that mean?

I'm referring to https://www.serverless.com/framework/docs/providers/aws/guide/functions/.

Thanks in advance.

1 Answers

There is no special meaning of - -; both dashes act according to their general semantics:

A - starts a YAML sequence item. Sibling sequence items at the same indentation level form a sequence. So, this is a sequence consisting of two sequence items:

- a
- b

Now the content of a sequence item is any valid YAML node. A sequence is a valid YAML node. Thus, this is allowed:

- a
- - b
  - c

This YAML document is a sequence with two items, the first one being a scalar a, the second one being a nested sequence with two items, the scalars b and c. YAML calls this compact notation because the usual notation would be

- a
- 
  - b
  - c

This longer notation allows giving the nested sequence an anchor (e.g. &a), a tag (e.g. !!seq) or both at its header line. Those are rather exotic features that are seldom used, and if don't need them, you can use the compact notation instead, which leads to two - -.

Related