Skip to content
v2.277.0

ApplicationLoadBalancedTaskImageProps Struct ​

Options for configuring a new container.

Example ​

ts
import { Certificate } from 'aws-cdk-lib/aws-certificatemanager';
import { InstanceType } from 'aws-cdk-lib/aws-ec2';
import { Cluster, ContainerImage } from 'aws-cdk-lib/aws-ecs';
import { ApplicationProtocol, SslPolicy } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import { PublicHostedZone } from 'aws-cdk-lib/aws-route53';
const vpc = new ec2.Vpc(this, 'Vpc', { maxAzs: 1 });
const loadBalancedFargateService = new ecsPatterns.ApplicationMultipleTargetGroupsFargateService(this, 'myService', {
  cluster: new ecs.Cluster(this, 'EcsCluster', { vpc }),
  memoryLimitMiB: 256,
  taskImageOptions: {
    image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
  },
  enableExecuteCommand: true,
  loadBalancers: [
    {
      name: 'lb',
      idleTimeout: Duration.seconds(400),
      domainName: 'api.example.com',
      domainZone: new PublicHostedZone(this, 'HostedZone', { zoneName: 'example.com' }),
      listeners: [
        {
          name: 'listener',
          protocol: ApplicationProtocol.HTTPS,
          certificate: Certificate.fromCertificateArn(this, 'Cert', 'helloworld'),
          sslPolicy: SslPolicy.TLS12_EXT,
        },
      ],
    },
    {
      name: 'lb2',
      idleTimeout: Duration.seconds(120),
      domainName: 'frontend.com',
      domainZone: new PublicHostedZone(this, 'HostedZone', { zoneName: 'frontend.com' }),
      listeners: [
        {
          name: 'listener2',
          protocol: ApplicationProtocol.HTTPS,
          certificate: Certificate.fromCertificateArn(this, 'Cert2', 'helloworld'),
          sslPolicy: SslPolicy.TLS12_EXT,
        },
      ],
    },
  ],
  targetGroups: [
    {
      containerPort: 80,
      listener: 'listener',
    },
    {
      containerPort: 90,
      pathPattern: 'a/b/c',
      priority: 10,
      listener: 'listener',
    },
    {
      containerPort: 443,
      listener: 'listener2',
    },
    {
      containerPort: 80,
      pathPattern: 'a/b/c',
      priority: 10,
      listener: 'listener2',
    },
  ],
});
python
from aws_cdk.aws_certificatemanager import Certificate
from aws_cdk.aws_ec2 import InstanceType
from aws_cdk.aws_ecs import Cluster, ContainerImage
from aws_cdk.aws_elasticloadbalancingv2 import ApplicationProtocol, SslPolicy
from aws_cdk.aws_route53 import PublicHostedZone

vpc = ec2.Vpc(self, "Vpc", max_azs=1)
load_balanced_fargate_service = ecs_patterns.ApplicationMultipleTargetGroupsFargateService(self, "myService",
    cluster=ecs.Cluster(self, "EcsCluster", vpc=vpc),
    memory_limit_mi_b=256,
    task_image_options=ecsPatterns.ApplicationLoadBalancedTaskImageProps(
        image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample")
    ),
    enable_execute_command=True,
    load_balancers=[ecsPatterns.ApplicationLoadBalancerProps(
        name="lb",
        idle_timeout=Duration.seconds(400),
        domain_name="api.example.com",
        domain_zone=PublicHostedZone(self, "HostedZone", zone_name="example.com"),
        listeners=[ecsPatterns.ApplicationListenerProps(
            name="listener",
            protocol=ApplicationProtocol.HTTPS,
            certificate=Certificate.from_certificate_arn(self, "Cert", "helloworld"),
            ssl_policy=SslPolicy.TLS12_EXT
        )
        ]
    ), ecsPatterns.ApplicationLoadBalancerProps(
        name="lb2",
        idle_timeout=Duration.seconds(120),
        domain_name="frontend.com",
        domain_zone=PublicHostedZone(self, "HostedZone", zone_name="frontend.com"),
        listeners=[ecsPatterns.ApplicationListenerProps(
            name="listener2",
            protocol=ApplicationProtocol.HTTPS,
            certificate=Certificate.from_certificate_arn(self, "Cert2", "helloworld"),
            ssl_policy=SslPolicy.TLS12_EXT
        )
        ]
    )
    ],
    target_groups=[ecsPatterns.ApplicationTargetProps(
        container_port=80,
        listener="listener"
    ), ecsPatterns.ApplicationTargetProps(
        container_port=90,
        path_pattern="a/b/c",
        priority=10,
        listener="listener"
    ), ecsPatterns.ApplicationTargetProps(
        container_port=443,
        listener="listener2"
    ), ecsPatterns.ApplicationTargetProps(
        container_port=80,
        path_pattern="a/b/c",
        priority=10,
        listener="listener2"
    )
    ]
)
java
import software.amazon.awscdk.services.certificatemanager.Certificate;
import software.amazon.awscdk.services.ec2.InstanceType;
import software.amazon.awscdk.services.ecs.Cluster;
import software.amazon.awscdk.services.ecs.ContainerImage;
import software.amazon.awscdk.services.elasticloadbalancingv2.ApplicationProtocol;
import software.amazon.awscdk.services.elasticloadbalancingv2.SslPolicy;
import software.amazon.awscdk.services.route53.PublicHostedZone;

Vpc vpc = Vpc.Builder.create(this, "Vpc").maxAzs(1).build();
ApplicationMultipleTargetGroupsFargateService loadBalancedFargateService = ApplicationMultipleTargetGroupsFargateService.Builder.create(this, "myService")
        .cluster(Cluster.Builder.create(this, "EcsCluster").vpc(vpc).build())
        .memoryLimitMiB(256)
        .taskImageOptions(ApplicationLoadBalancedTaskImageProps.builder()
                .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
                .build())
        .enableExecuteCommand(true)
        .loadBalancers(List.of(ApplicationLoadBalancerProps.builder()
                .name("lb")
                .idleTimeout(Duration.seconds(400))
                .domainName("api.example.com")
                .domainZone(PublicHostedZone.Builder.create(this, "HostedZone").zoneName("example.com").build())
                .listeners(List.of(ApplicationListenerProps.builder()
                        .name("listener")
                        .protocol(ApplicationProtocol.HTTPS)
                        .certificate(Certificate.fromCertificateArn(this, "Cert", "helloworld"))
                        .sslPolicy(SslPolicy.TLS12_EXT)
                        .build()))
                .build(), ApplicationLoadBalancerProps.builder()
                .name("lb2")
                .idleTimeout(Duration.seconds(120))
                .domainName("frontend.com")
                .domainZone(PublicHostedZone.Builder.create(this, "HostedZone").zoneName("frontend.com").build())
                .listeners(List.of(ApplicationListenerProps.builder()
                        .name("listener2")
                        .protocol(ApplicationProtocol.HTTPS)
                        .certificate(Certificate.fromCertificateArn(this, "Cert2", "helloworld"))
                        .sslPolicy(SslPolicy.TLS12_EXT)
                        .build()))
                .build()))
        .targetGroups(List.of(ApplicationTargetProps.builder()
                .containerPort(80)
                .listener("listener")
                .build(), ApplicationTargetProps.builder()
                .containerPort(90)
                .pathPattern("a/b/c")
                .priority(10)
                .listener("listener")
                .build(), ApplicationTargetProps.builder()
                .containerPort(443)
                .listener("listener2")
                .build(), ApplicationTargetProps.builder()
                .containerPort(80)
                .pathPattern("a/b/c")
                .priority(10)
                .listener("listener2")
                .build()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.CertificateManager;
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.ECS;
using Amazon.CDK.AWS.ElasticLoadBalancingV2;
using Amazon.CDK.AWS.Route53;

var vpc = new Vpc(this, "Vpc", new VpcProps { MaxAzs = 1 });
var loadBalancedFargateService = new ApplicationMultipleTargetGroupsFargateService(this, "myService", new ApplicationMultipleTargetGroupsFargateServiceProps {
    Cluster = new Cluster(this, "EcsCluster", new ClusterProps { Vpc = vpc }),
    MemoryLimitMiB = 256,
    TaskImageOptions = new ApplicationLoadBalancedTaskImageProps {
        Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample")
    },
    EnableExecuteCommand = true,
    LoadBalancers = new [] { new ApplicationLoadBalancerProps {
        Name = "lb",
        IdleTimeout = Duration.Seconds(400),
        DomainName = "api.example.com",
        DomainZone = new PublicHostedZone(this, "HostedZone", new PublicHostedZoneProps { ZoneName = "example.com" }),
        Listeners = new [] { new ApplicationListenerProps {
            Name = "listener",
            Protocol = ApplicationProtocol.HTTPS,
            Certificate = Certificate.FromCertificateArn(this, "Cert", "helloworld"),
            SslPolicy = SslPolicy.TLS12_EXT
        } }
    }, new ApplicationLoadBalancerProps {
        Name = "lb2",
        IdleTimeout = Duration.Seconds(120),
        DomainName = "frontend.com",
        DomainZone = new PublicHostedZone(this, "HostedZone", new PublicHostedZoneProps { ZoneName = "frontend.com" }),
        Listeners = new [] { new ApplicationListenerProps {
            Name = "listener2",
            Protocol = ApplicationProtocol.HTTPS,
            Certificate = Certificate.FromCertificateArn(this, "Cert2", "helloworld"),
            SslPolicy = SslPolicy.TLS12_EXT
        } }
    } },
    TargetGroups = new [] { new ApplicationTargetProps {
        ContainerPort = 80,
        Listener = "listener"
    }, new ApplicationTargetProps {
        ContainerPort = 90,
        PathPattern = "a/b/c",
        Priority = 10,
        Listener = "listener"
    }, new ApplicationTargetProps {
        ContainerPort = 443,
        Listener = "listener2"
    }, new ApplicationTargetProps {
        ContainerPort = 80,
        PathPattern = "a/b/c",
        Priority = 10,
        Listener = "listener2"
    } }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

vpc := ec2.NewVpc(this, jsii.String("Vpc"), &VpcProps{
	MaxAzs: jsii.Number(1),
})
loadBalancedFargateService := ecsPatterns.NewApplicationMultipleTargetGroupsFargateService(this, jsii.String("myService"), &ApplicationMultipleTargetGroupsFargateServiceProps{
	Cluster: ecs.NewCluster(this, jsii.String("EcsCluster"), &ClusterProps{
		Vpc: *Vpc,
	}),
	MemoryLimitMiB: jsii.Number(256),
	TaskImageOptions: &ApplicationLoadBalancedTaskImageProps{
		Image: ecs.ContainerImage_FromRegistry(jsii.String("amazon/amazon-ecs-sample")),
	},
	EnableExecuteCommand: jsii.Boolean(true),
	LoadBalancers: []ApplicationLoadBalancerProps{
		&ApplicationLoadBalancerProps{
			Name: jsii.String("lb"),
			IdleTimeout: awscdk.Duration_Seconds(jsii.Number(400)),
			DomainName: jsii.String("api.example.com"),
			DomainZone: awscdk.NewPublicHostedZone(this, jsii.String("HostedZone"), &PublicHostedZoneProps{
				ZoneName: jsii.String("example.com"),
			}),
			Listeners: []ApplicationListenerProps{
				&ApplicationListenerProps{
					Name: jsii.String("listener"),
					Protocol: awscdk.ApplicationProtocol_HTTPS,
					Certificate: awscdk.Certificate_FromCertificateArn(this, jsii.String("Cert"), jsii.String("helloworld")),
					SslPolicy: awscdk.SslPolicy_TLS12_EXT,
				},
			},
		},
		&ApplicationLoadBalancerProps{
			Name: jsii.String("lb2"),
			IdleTimeout: awscdk.Duration_*Seconds(jsii.Number(120)),
			DomainName: jsii.String("frontend.com"),
			DomainZone: awscdk.NewPublicHostedZone(this, jsii.String("HostedZone"), &PublicHostedZoneProps{
				ZoneName: jsii.String("frontend.com"),
			}),
			Listeners: []ApplicationListenerProps{
				&ApplicationListenerProps{
					Name: jsii.String("listener2"),
					Protocol: awscdk.ApplicationProtocol_HTTPS,
					Certificate: awscdk.Certificate_*FromCertificateArn(this, jsii.String("Cert2"), jsii.String("helloworld")),
					SslPolicy: awscdk.SslPolicy_TLS12_EXT,
				},
			},
		},
	},
	TargetGroups: []ApplicationTargetProps{
		&ApplicationTargetProps{
			ContainerPort: jsii.Number(80),
			Listener: jsii.String("listener"),
		},
		&ApplicationTargetProps{
			ContainerPort: jsii.Number(90),
			PathPattern: jsii.String("a/b/c"),
			Priority: jsii.Number(10),
			Listener: jsii.String("listener"),
		},
		&ApplicationTargetProps{
			ContainerPort: jsii.Number(443),
			Listener: jsii.String("listener2"),
		},
		&ApplicationTargetProps{
			ContainerPort: jsii.Number(80),
			PathPattern: jsii.String("a/b/c"),
			Priority: jsii.Number(10),
			Listener: jsii.String("listener2"),
		},
	},
})

Properties ​

containerNameoptionalstringcontainer_nameoptionalstrcontainerNameoptionalStringContainerNameoptionalstringContainerNameoptional*string= web#
The container name value to be specified in the task definition.
containerPortsoptionalnumber[]container_portsoptionaltyping.List[int | float]containerPortsoptionalList<Number>ContainerPortsoptionaldouble[]ContainerPortsoptional*[]*float64= [80]#
A list of port numbers on the container that is bound to the user-specified or automatically assigned host port.
notes

If you are using containers in a task with the awsvpc or host network mode, exposed ports should be specified using containerPort. If you are using containers in a task with the bridge network mode and you specify a container port and not a host port, your container automatically receives a host port in the ephemeral port range.

Port mappings that are automatically assigned in this way do not count toward the 100 reserved ports limit of a container instance.

For more information, see hostPort.

dockerLabelsoptional{ [key: string]: string }docker_labelsoptionaltyping.Mapping[str, str]dockerLabelsoptionalMap<String, String>DockerLabelsoptionalIDictionary<string, string>DockerLabelsoptional*map[string]*string#
A key/value map of labels to add to the container.

Default: No labels.

enableLoggingoptionalbooleanenable_loggingoptionalboolenableLoggingoptionalBooleanEnableLoggingoptionalboolEnableLoggingoptional*bool= true#
Flag to indicate whether to enable logging.
environmentoptional{ [key: string]: string }environmentoptionaltyping.Mapping[str, str]environmentoptionalMap<String, String>EnvironmentoptionalIDictionary<string, string>Environmentoptional*map[string]*string#
The environment variables to pass to the container.

Default: No environment variables.

executionRoleoptionalIRoleexecution_roleoptionalIRoleexecutionRoleoptionalIRoleExecutionRoleoptionalIRoleExecutionRoleoptionalIRole#
The name of the task execution IAM role that grants the Amazon ECS container agent permission to call AWS APIs on your behalf.

Default: No value

familyoptionalstringfamilyoptionalstrfamilyoptionalStringFamilyoptionalstringFamilyoptional*string#
The name of a family that this task definition is registered to.

Default: Automatically generated name.

A family groups multiple versions of a task definition.

The image used to start a container.

Image or taskDefinition must be specified, not both.

logDriveroptionalLogDriverlog_driveroptionalLogDriverlogDriveroptionalLogDriverLogDriveroptionalLogDriverLogDriveroptionalLogDriver#
The log driver to use.

Default: AwsLogDriver if enableLogging is true

secretsoptional{ [key: string]: Secret }secretsoptionaltyping.Mapping[str, Secret]secretsoptionalMap<String, Secret>SecretsoptionalIDictionary<string, Secret>Secretsoptional*map[string]Secret#
The secrets to expose to the container as an environment variable.

Default: No secret environment variables.

taskRoleoptionalIRoletask_roleoptionalIRoletaskRoleoptionalIRoleTaskRoleoptionalIRoleTaskRoleoptionalIRole#
The name of the task IAM role that grants containers in the task permission to call AWS APIs on your behalf.

Default: A task role is automatically created for you.