How to add Tags to Private API Gateways in AWS SAM
Asked Answered
L

1

5

I have created an API Gateway using AWS::Serverless::API in SAM and now I want to add Tags to Gateway in order to enforce security constraints on every Gateway with the same tag.

  Type: AWS::Serverless::Api
  Properties:
    Name: PrivateApi
    StageName: v1
    Tags:
      - Key: TagName
        Value: TagValue
    MethodSettings:
    ...

After looking at the documentation I have came up with the code above. As the documentation states it supports Tags in the way shown above but when I deploy I get the following error.

samcli.commands.validate.lib.exceptions.InvalidSamDocumentException: [InvalidResourceException('PrivateApi', "Type of property 'Tags' is invalid.")] ('PrivateApi', "Type of property 'Tags' is invalid.")

Link to Documentation about Tags: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html

Any help on this would be appreciated!

Lorolla answered 10/3, 2020 at 18:44 Comment(0)
L
8

I figured out that the documentation on the AWS::Serverless::API page, and the Tags page is slightly wrong when using SAM.

The proper way of denoting a Tag in SAM is the following.

  Type: AWS::Serverless::Api
  Properties:
    Name: PrivateApi
    StageName: v1
    Tags:
      TagName: TagValue
    MethodSettings:
    ...

This subtle difference makes SAM deploy properly. As a helpful aside, in the API Stage you can verify that the Tag has been deployed properly.

Lorolla answered 10/3, 2020 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.