

# Using CloudFormation to create tags for AMS Accelerate
CloudFormation

You can use CloudFormation to apply tags at the stack level (see CloudFormation documentation, [ Resource tag](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html)) or at the individual resource level (for example, see [ Tagging your Amazon EC2 resources](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html)).

**Important**  
Some AMS Accelerate service components require tags with the **ams:rt:** prefix. Resource Tagger believes that it owns these tags, and will delete them if no Resource Tagger configuration rules permit them. You always need to deploy a Resource Tagger configuration profile for these tags, even if you are using CloudFormation or Terraform. 

# CloudFormation Use cases for AMS Accelerate
Use cases

This section lists commonly performed actions with CloudFormation.

**Topics**
+ [

# Tagging an EC2 instance with CloudFormation for Accelerate
](acc-tag-cf-ex-tag-ec2.md)
+ [

# Tagging an AutoScaling Group (ASG) with CloudFormation for Accelerate
](acc-tag-cf-ex-tag-asg.md)
+ [

# Deploying a configuration profile with CloudFormation for Accelerate
](acc-tag-cf-ex-deploy-config.md)

# Tagging an EC2 instance with CloudFormation for Accelerate
Tag EC2

The following is an example of how you can apply the tag **ams:rt:ams-managed** with the value **true** to an Amazon EC2 instance managed by CloudFormation. The **ams:rt:ams-managed** tag opts you in to having your resources monitored by AMS Accelerate.

```
 Type: AWS::EC2::Instance

Properties: 
  InstanceType: "t3.micro"
  
  # ...other properties...
  
  Tags: 
    - Key: "ams:rt:ams-managed"
      Value: "true"
```

# Tagging an AutoScaling Group (ASG) with CloudFormation for Accelerate
Tag ASG

The following is an example of how you can apply the tag **ams:rt:ams-managed** with the value **true** to an Auto Scaling group managed by CloudFormation. Note that the Auto Scaling group will propagate its tags to Amazon EC2 instances that are created by it. The **ams:rt:ams-managed** tag opts you in to having your resources monitored by AMS Accelerate.

```
  Type: AWS::AutoScaling::AutoScalingGroup
Properties: 
  AutoScalingGroupName: "SampleASG"
  
  # ...other properties...
  
  Tags: 
    - Key: "ams:rt:ams-managed"
      Value: "true"
```

# Deploying a configuration profile with CloudFormation for Accelerate
Deploy config profile

If you wish to deploy your `CustomerManagedTags` configuration profile using CloudFormation, you can use the following CloudFormation templates. Put your desired JSON configuration in the `AMSResourceTaggerConfigurationVersion.Content` field.

 When you deploy the templates in a CloudFormation Stack or Stack Set, the deployment of the `AMSResourceTaggerDeployment ` resource will fail if you have not followed the required JSON format for the configuration. See [Syntax and structure](acc-tag-tools-profiles.md#acc-rt-config-doc-format) for details on the expected format. 

 For help on deploying these templates as a CloudFormation stack or stack set, see the relevant AWS CloudFormation documentation below: 
+  [ Creating a stack on the AWS CloudFormation console ](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-create-stack.html) 
+  [ Creating a stack with AWS CLI](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-cli-creating-stack.html) 
+  [ Creating a stack set ](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-getting-started-create.html) 

**Note**  
If you deploy a configuration version using one of these templates, and then subsequently delete the CloudFormation stack/stack set, the template configuration version will remain as the current deployed version, and no additional deployment will be made. If you wish to revert back to a default configuration, you will need to either manually deploy an empty configuration (that is, just `{}`), or update your stack to an empty configuration, rather than deleting the stack. 

**JSON**

```
{
  "Description": "Custom configuration for the AMS Resource Tagger.",
  "Resources": {
    "AMSResourceTaggerConfigurationVersion": {
      "Type": "AWS::AppConfig::HostedConfigurationVersion",
      "Properties": {
        "ApplicationId": {
          "Fn::ImportValue": "AMS-ResourceTagger-Configuration-ApplicationId"
        },
        "ConfigurationProfileId": {
          "Fn::ImportValue": "AMS-ResourceTagger-Configuration-CustomerManagedTags-ProfileID"
        },
        "Content": "{\"Options\": {\"ReadOnly\": false}}",
        "ContentType": "application/json"
      }
    },
    "AMSResourceTaggerDeployment": {
      "Type": "AWS::AppConfig::Deployment",
      "Properties": {
        "ApplicationId": {
          "Fn::ImportValue": "AMS-ResourceTagger-Configuration-ApplicationId"
        },
        "ConfigurationProfileId": {
          "Fn::ImportValue": "AMS-ResourceTagger-Configuration-CustomerManagedTags-ProfileID"
        },
        "ConfigurationVersion": {
          "Ref": "AMSResourceTaggerConfigurationVersion"
        },
        "DeploymentStrategyId": {
          "Fn::ImportValue": "AMS-ResourceTagger-Configuration-Deployment-StrategyID"
        }, 
        "EnvironmentId": {
          "Fn::ImportValue": "AMS-ResourceTagger-Configuration-EnvironmentId"
        }
      }
    }
  }
}
```

**YAML**

```
Description: Custom configuration for the AMS Resource Tagger.
Resources:
  AMSResourceTaggerConfigurationVersion:
    Type: AWS::AppConfig::HostedConfigurationVersion
    Properties:
      ApplicationId:
        !ImportValue AMS-ResourceTagger-Configuration-ApplicationId
      ConfigurationProfileId:
        !ImportValue AMS-ResourceTagger-Configuration-CustomerManagedTags-ProfileID
      Content: |
        {
          "Options": {
            "ReadOnly": false
          }
        }
      ContentType: application/json
  AMSResourceTaggerDeployment:
    Type: AWS::AppConfig::Deployment
    Properties:
      ApplicationId:
        !ImportValue AMS-ResourceTagger-Configuration-ApplicationId
      ConfigurationProfileId:
        !ImportValue AMS-ResourceTagger-Configuration-CustomerManagedTags-ProfileID
      ConfigurationVersion:
        !Ref AMSResourceTaggerConfigurationVersion
      DeploymentStrategyId:
        !ImportValue AMS-ResourceTagger-Configuration-Deployment-StrategyID
      EnvironmentId:
        !ImportValue AMS-ResourceTagger-Configuration-EnvironmentId
```