Skip to content
v2.273.0

InstanceTagSet Class ​

Represents a set of instance tag groups.

An instance will match a set if it matches all of the groups in the set - in other words, sets follow 'and' semantics. You can have a maximum of 3 tag groups inside a set.

Example ​

ts
import * as autoscaling from 'aws-cdk-lib/aws-autoscaling';
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';

declare const application: codedeploy.ServerApplication;
declare const asg: autoscaling.AutoScalingGroup;
declare const alarm: cloudwatch.Alarm;
const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'CodeDeployDeploymentGroup', {
  application,
  deploymentGroupName: 'MyDeploymentGroup',
  autoScalingGroups: [asg],
  // adds User Data that installs the CodeDeploy agent on your auto-scaling groups hosts
  // default: true
  installAgent: true,
  // adds EC2 instances matching tags
  ec2InstanceTags: new codedeploy.InstanceTagSet(
    {
      // any instance with tags satisfying
      // key1=v1 or key1=v2 or key2 (any value) or value v3 (any key)
      // will match this group
      'key1': ['v1', 'v2'],
      'key2': [],
      '': ['v3'],
    },
  ),
  // adds on-premise instances matching tags
  onPremiseInstanceTags: new codedeploy.InstanceTagSet(
    // only instances with tags (key1=v1 or key1=v2) AND key2=v3 will match this set
    {
      'key1': ['v1', 'v2'],
    },
    {
      'key2': ['v3'],
    },
  ),
  // CloudWatch alarms
  alarms: [alarm],
  // whether to ignore failure to fetch the status of alarms from CloudWatch
  // default: false
  ignorePollAlarmsFailure: false,
  // whether to skip the step of checking CloudWatch alarms during the deployment process
  // default: false
  ignoreAlarmConfiguration: false,
  // auto-rollback configuration
  autoRollback: {
    failedDeployment: true, // default: true
    stoppedDeployment: true, // default: false
    deploymentInAlarm: true, // default: true if you provided any alarms, false otherwise
  },
  // whether the deployment group was configured to have CodeDeploy install a termination hook into an Auto Scaling group
  // default: false
  terminationHook: true,
});
python
import aws_cdk.aws_autoscaling as autoscaling
import aws_cdk.aws_cloudwatch as cloudwatch

# application: codedeploy.ServerApplication
# asg: autoscaling.AutoScalingGroup
# alarm: cloudwatch.Alarm

deployment_group = codedeploy.ServerDeploymentGroup(self, "CodeDeployDeploymentGroup",
    application=application,
    deployment_group_name="MyDeploymentGroup",
    auto_scaling_groups=[asg],
    # adds User Data that installs the CodeDeploy agent on your auto-scaling groups hosts
    # default: true
    install_agent=True,
    # adds EC2 instances matching tags
    ec2_instance_tags=codedeploy.InstanceTagSet({
        # any instance with tags satisfying
        # key1=v1 or key1=v2 or key2 (any value) or value v3 (any key)
        # will match this group
        "key1": ["v1", "v2"],
        "key2": [],
        "": ["v3"]
    }),
    # adds on-premise instances matching tags
    on_premise_instance_tags=codedeploy.InstanceTagSet({
        "key1": ["v1", "v2"]
    }, {
        "key2": ["v3"]
    }),
    # CloudWatch alarms
    alarms=[alarm],
    # whether to ignore failure to fetch the status of alarms from CloudWatch
    # default: false
    ignore_poll_alarms_failure=False,
    # whether to skip the step of checking CloudWatch alarms during the deployment process
    # default: false
    ignore_alarm_configuration=False,
    # auto-rollback configuration
    auto_rollback=codedeploy.AutoRollbackConfig(
        failed_deployment=True,  # default: true
        stopped_deployment=True,  # default: false
        deployment_in_alarm=True
    ),
    # whether the deployment group was configured to have CodeDeploy install a termination hook into an Auto Scaling group
    # default: false
    termination_hook=True
)
java
import software.amazon.awscdk.services.autoscaling.*;
import software.amazon.awscdk.services.cloudwatch.*;

ServerApplication application;
AutoScalingGroup asg;
Alarm alarm;

ServerDeploymentGroup deploymentGroup = ServerDeploymentGroup.Builder.create(this, "CodeDeployDeploymentGroup")
        .application(application)
        .deploymentGroupName("MyDeploymentGroup")
        .autoScalingGroups(List.of(asg))
        // adds User Data that installs the CodeDeploy agent on your auto-scaling groups hosts
        // default: true
        .installAgent(true)
        // adds EC2 instances matching tags
        .ec2InstanceTags(new InstanceTagSet(Map.of(
                // any instance with tags satisfying
                // key1=v1 or key1=v2 or key2 (any value) or value v3 (any key)
                // will match this group
                "key1", List.of("v1", "v2"),
                "key2", List.of(),
                "", List.of("v3"))))
        // adds on-premise instances matching tags
        .onPremiseInstanceTags(new InstanceTagSet(Map.of(
                "key1", List.of("v1", "v2")), Map.of(
                "key2", List.of("v3"))))
        // CloudWatch alarms
        .alarms(List.of(alarm))
        // whether to ignore failure to fetch the status of alarms from CloudWatch
        // default: false
        .ignorePollAlarmsFailure(false)
        // whether to skip the step of checking CloudWatch alarms during the deployment process
        // default: false
        .ignoreAlarmConfiguration(false)
        // auto-rollback configuration
        .autoRollback(AutoRollbackConfig.builder()
                .failedDeployment(true) // default: true
                .stoppedDeployment(true) // default: false
                .deploymentInAlarm(true)
                .build())
        // whether the deployment group was configured to have CodeDeploy install a termination hook into an Auto Scaling group
        // default: false
        .terminationHook(true)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.AutoScaling;
using Amazon.CDK.AWS.CloudWatch;

ServerApplication application;
AutoScalingGroup asg;
Alarm alarm;

var deploymentGroup = new ServerDeploymentGroup(this, "CodeDeployDeploymentGroup", new ServerDeploymentGroupProps {
    Application = application,
    DeploymentGroupName = "MyDeploymentGroup",
    AutoScalingGroups = new [] { asg },
    // adds User Data that installs the CodeDeploy agent on your auto-scaling groups hosts
    // default: true
    InstallAgent = true,
    // adds EC2 instances matching tags
    Ec2InstanceTags = new InstanceTagSet(new Dictionary<string, string[]> {
        // any instance with tags satisfying
        // key1=v1 or key1=v2 or key2 (any value) or value v3 (any key)
        // will match this group
        { "key1", new [] { "v1", "v2" } },
        { "key2", new [] {  } },
        { "", new [] { "v3" } }
    }),
    // adds on-premise instances matching tags
    OnPremiseInstanceTags = new InstanceTagSet(new Dictionary<string, string[]> {
        { "key1", new [] { "v1", "v2" } }
    }, new Dictionary<string, string[]> {
        { "key2", new [] { "v3" } }
    }),
    // CloudWatch alarms
    Alarms = new [] { alarm },
    // whether to ignore failure to fetch the status of alarms from CloudWatch
    // default: false
    IgnorePollAlarmsFailure = false,
    // whether to skip the step of checking CloudWatch alarms during the deployment process
    // default: false
    IgnoreAlarmConfiguration = false,
    // auto-rollback configuration
    AutoRollback = new AutoRollbackConfig {
        FailedDeployment = true,  // default: true
        StoppedDeployment = true,  // default: false
        DeploymentInAlarm = true
    },
    // whether the deployment group was configured to have CodeDeploy install a termination hook into an Auto Scaling group
    // default: false
    TerminationHook = true
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import autoscaling "github.com/aws/aws-cdk-go/awscdk"
import cloudwatch "github.com/aws/aws-cdk-go/awscdk"

var application ServerApplication
var asg AutoScalingGroup
var alarm Alarm

deploymentGroup := codedeploy.NewServerDeploymentGroup(this, jsii.String("CodeDeployDeploymentGroup"), &ServerDeploymentGroupProps{
	Application: Application,
	DeploymentGroupName: jsii.String("MyDeploymentGroup"),
	AutoScalingGroups: []IAutoScalingGroup{
		asg,
	},
	// adds User Data that installs the CodeDeploy agent on your auto-scaling groups hosts
	// default: true
	InstallAgent: jsii.Boolean(true),
	// adds EC2 instances matching tags
	Ec2InstanceTags: codedeploy.NewInstanceTagSet(map[string][]*string{
		// any instance with tags satisfying
		// key1=v1 or key1=v2 or key2 (any value) or value v3 (any key)
		// will match this group
		"key1": []*string{
			jsii.String("v1"),
			jsii.String("v2"),
		},
		"key2": []*string{
		},
		"": []*string{
			jsii.String("v3"),
		},
	}),
	// adds on-premise instances matching tags
	OnPremiseInstanceTags: codedeploy.NewInstanceTagSet(map[string][]*string{
		"key1": []*string{
			jsii.String("v1"),
			jsii.String("v2"),
		},
	}, map[string][]*string{
		"key2": []*string{
			jsii.String("v3"),
		},
	}),
	// CloudWatch alarms
	Alarms: []IAlarmRef{
		alarm,
	},
	// whether to ignore failure to fetch the status of alarms from CloudWatch
	// default: false
	IgnorePollAlarmsFailure: jsii.Boolean(false),
	// whether to skip the step of checking CloudWatch alarms during the deployment process
	// default: false
	IgnoreAlarmConfiguration: jsii.Boolean(false),
	// auto-rollback configuration
	AutoRollback: &AutoRollbackConfig{
		FailedDeployment: jsii.Boolean(true),
		 // default: true
		StoppedDeployment: jsii.Boolean(true),
		 // default: false
		DeploymentInAlarm: jsii.Boolean(true),
	},
	// whether the deployment group was configured to have CodeDeploy install a termination hook into an Auto Scaling group
	// default: false
	TerminationHook: jsii.Boolean(true),
})

Initializer ​

ts
new InstanceTagSet(instanceTagGroups: { [key: string]: string[] })
python
InstanceTagSet(instance_tag_groups: typing.Mapping[str, typing.List[str]])
java
new InstanceTagSet(Map<String, List<String>> instanceTagGroups)
csharp
new InstanceTagSet(IDictionary<string, string[]> instanceTagGroups)
go
NewInstanceTagSet(InstanceTagGroups *map[string]*[]*string)

Properties ​

instanceTagGroups{ [key: string]: string[] }[]instance_tag_groupstyping.List[typing.Mapping[str, typing.List[str]]]instanceTagGroupsList<Map<String, List<String>>>InstanceTagGroupsIDictionary<string, string[]>[]InstanceTagGroups*[]*map[string]*[]*stringrequired#