class ExternalService (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.ECS.ExternalService |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsecs#ExternalService |
![]() | software.amazon.awscdk.services.ecs.ExternalService |
![]() | aws_cdk.aws_ecs.ExternalService |
![]() | aws-cdk-lib » aws_ecs » ExternalService |
Implements
IConstruct
, IDependable
, IResource
, IBase
, IService
, IApplication
, INetwork
, ILoad
, IConnectable
, IExternal
This creates a service using the External launch type on an ECS cluster.
Example
declare const cluster: ecs.Cluster;
declare const taskDefinition: ecs.TaskDefinition;
new ecs.Ec2Service(this, 'Ec2Service', {
cluster,
taskDefinition,
daemon: true,
});
new ecs.ExternalService(this, 'ExternalService', {
cluster,
taskDefinition,
daemon: true,
});
Initializer
new ExternalService(scope: Construct, id: string, props: ExternalServiceProps)
Parameters
- scope
Construct
- id
string
- props
External
Service Props
Constructs a new instance of the ExternalService class.
Construct Props
Name | Type | Description |
---|---|---|
cluster | ICluster | The name of the cluster that hosts the service. |
task | Task | The task definition to use for tasks in the service. |
capacity | Capacity [] | A list of Capacity Provider strategies used to place a service. |
circuit | Deployment | Whether to enable the deployment circuit breaker. |
cloud | Cloud | The options for configuring an Amazon ECS service to use service discovery. |
daemon? | boolean | By default, service use REPLICA scheduling strategy, this parameter enable DAEMON scheduling strategy. |
deployment | Deployment | The alarm(s) to monitor during deployment, and behavior to apply if at least one enters a state of alarm during the deployment or bake time. |
deployment | Deployment | Specifies which deployment controller to use for the service. |
desired | number | The desired number of instantiations of the task definition to keep running on the service. |
enable | boolean | Specifies whether to enable Amazon ECS managed tags for the tasks within the service. |
enable | boolean | Whether to enable the ability to execute into a container. |
health | Duration | The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy Elastic Load Balancing target health checks after a task has first started. |
max | number | The maximum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that can run in a service during a deployment. |
min | number | The minimum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that must continue to run and remain healthy during a deployment. |
propagate | Propagated | Specifies whether to propagate the tags from the task definition or the service to the tasks in the service. |
security | ISecurity [] | The security groups to associate with the service. |
service | Service | Configuration for Service Connect. |
service | string | The name of the service. |
task | Task | Revision number for the task definition or latest to use the latest active task revision. |
volume | Service [] | Configuration details for a volume used by the service. |
cluster
Type:
ICluster
The name of the cluster that hosts the service.
taskDefinition
Type:
Task
The task definition to use for tasks in the service.
[disable-awslint:ref-via-interface]
capacityProviderStrategies?
Type:
Capacity
[]
(optional, default: undefined)
A list of Capacity Provider strategies used to place a service.
circuitBreaker?
Type:
Deployment
(optional, default: disabled)
Whether to enable the deployment circuit breaker.
If this property is defined, circuit breaker will be implicitly enabled.
cloudMapOptions?
Type:
Cloud
(optional, default: AWS Cloud Map service discovery is not enabled.)
The options for configuring an Amazon ECS service to use service discovery.
daemon?
Type:
boolean
(optional, default: false)
By default, service use REPLICA scheduling strategy, this parameter enable DAEMON scheduling strategy.
If true, the service scheduler deploys exactly one task on each container instance in your cluster.
When you are using this strategy, do not specify a desired number of tasks or any task placement strategies. Tasks using the Fargate launch type or the CODE_DEPLOY or EXTERNAL deployment controller types don't support the DAEMON scheduling strategy.
deploymentAlarms?
Type:
Deployment
(optional, default: No alarms will be monitored during deployment.)
The alarm(s) to monitor during deployment, and behavior to apply if at least one enters a state of alarm during the deployment or bake time.
deploymentController?
Type:
Deployment
(optional, default: Rolling update (ECS))
Specifies which deployment controller to use for the service.
For more information, see Amazon ECS Deployment Types
desiredCount?
Type:
number
(optional, default: When creating the service, default is 1; when updating the service, default uses
the current task number.)
The desired number of instantiations of the task definition to keep running on the service.
enableECSManagedTags?
Type:
boolean
(optional, default: false)
Specifies whether to enable Amazon ECS managed tags for the tasks within the service.
For more information, see Tagging Your Amazon ECS Resources
enableExecuteCommand?
Type:
boolean
(optional, default: undefined)
Whether to enable the ability to execute into a container.
healthCheckGracePeriod?
Type:
Duration
(optional, default: defaults to 60 seconds if at least one load balancer is in-use and it is not already set)
The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy Elastic Load Balancing target health checks after a task has first started.
maxHealthyPercent?
Type:
number
(optional, default: 100 if daemon, otherwise 200)
The maximum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that can run in a service during a deployment.
minHealthyPercent?
Type:
number
(optional, default: 0 if daemon, otherwise 50)
The minimum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that must continue to run and remain healthy during a deployment.
propagateTags?
Type:
Propagated
(optional, default: PropagatedTagSource.NONE)
Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.
Valid values are: PropagatedTagSource.SERVICE, PropagatedTagSource.TASK_DEFINITION or PropagatedTagSource.NONE
securityGroups?
Type:
ISecurity
[]
(optional, default: A new security group is created.)
The security groups to associate with the service.
If you do not specify a security group, a new security group is created.
serviceConnectConfiguration?
Type:
Service
(optional, default: No ports are advertised via Service Connect on this service, and the service
cannot make requests to other services via Service Connect.)
Configuration for Service Connect.
serviceName?
Type:
string
(optional, default: CloudFormation-generated name.)
The name of the service.
taskDefinitionRevision?
Type:
Task
(optional, default: Uses the revision of the passed task definition deployed by CloudFormation)
Revision number for the task definition or latest
to use the latest active task revision.
volumeConfigurations?
Type:
Service
[]
(optional, default: undefined)
Configuration details for a volume used by the service.
This allows you to specify details about the EBS volume that can be attched to ECS tasks.
Properties
Name | Type | Description |
---|---|---|
cluster | ICluster | The cluster that hosts the service. |
connections | Connections | The security groups which manage the allowed network traffic for the service. |
env | Resource | The environment this resource belongs to. |
node | Node | The tree node. |
service | string | The Amazon Resource Name (ARN) of the service. |
service | string | The name of the service. |
stack | Stack | The stack in which this resource is defined. |
task | Task | The task definition to use for tasks in the service. |
cloud | IService | The CloudMap service created for this service, if any. |
cluster
Type:
ICluster
The cluster that hosts the service.
connections
Type:
Connections
The security groups which manage the allowed network traffic for the service.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
node
Type:
Node
The tree node.
serviceArn
Type:
string
The Amazon Resource Name (ARN) of the service.
serviceName
Type:
string
The name of the service.
stack
Type:
Stack
The stack in which this resource is defined.
taskDefinition
Type:
Task
The task definition to use for tasks in the service.
cloudMapService?
Type:
IService
(optional)
The CloudMap service created for this service, if any.
Methods
Name | Description |
---|---|
add | Adds a volume to the Service. |
apply | Apply the given removal policy to this resource. |
associate | Overridden method to throw error as associateCloudMapService is not supported for external service. |
attach | Overridden method to throw error as attachToApplicationTargetGroup is not supported for external service. |
attach | Registers the service as a target of a Classic Load Balancer (CLB). |
attach | This method is called to attach this service to a Network Load Balancer. |
auto | Overridden method to throw error as autoScaleTaskCount is not supported for external service. |
enable | Overridden method to throw error as enableCloudMap is not supported for external service. |
enable | Enable Deployment Alarms which take advantage of arbitrary alarms and configure them after service initialization. |
enable | Enable Service Connect on this service. |
load | Overridden method to throw error as loadBalancerTarget is not supported for external service. |
metric(metricName, props?) | This method returns the specified CloudWatch metric name for this service. |
metric | This method returns the CloudWatch metric for this service's CPU utilization. |
metric | This method returns the CloudWatch metric for this service's memory utilization. |
register | Overridden method to throw error as registerLoadBalancerTargets is not supported for external service. |
to | Returns a string representation of this construct. |
protected configure | Overridden method to throw error as configureAwsVpcNetworkingWithSecurityGroups is not supported for external service. |
static from | Imports from the specified service ARN. |
static from | Imports from the specified service attributes. |
addVolume(volume)
public addVolume(volume: ServiceManagedVolume): void
Parameters
- volume
Service
Managed Volume
Adds a volume to the Service.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
associateCloudMapService(_options)
public associateCloudMapService(_options: AssociateCloudMapServiceOptions): void
Parameters
- _options
Associate
Cloud Map Service Options
Overridden method to throw error as associateCloudMapService
is not supported for external service.
attachToApplicationTargetGroup(_targetGroup)
public attachToApplicationTargetGroup(_targetGroup: IApplicationTargetGroup): LoadBalancerTargetProps
Parameters
- _targetGroup
IApplication
Target Group
Returns
Overridden method to throw error as attachToApplicationTargetGroup
is not supported for external service.
attachToClassicLB(loadBalancer)
public attachToClassicLB(loadBalancer: LoadBalancer): void
Parameters
- loadBalancer
Load
— [disable-awslint:ref-via-interface].Balancer
Registers the service as a target of a Classic Load Balancer (CLB).
Don't call this. Call loadBalancer.addTarget()
instead.
attachToNetworkTargetGroup(targetGroup)
public attachToNetworkTargetGroup(targetGroup: INetworkTargetGroup): LoadBalancerTargetProps
Parameters
- targetGroup
INetwork
Target Group
Returns
This method is called to attach this service to a Network Load Balancer.
Don't call this function directly. Instead, call listener.addTargets()
to add this service to a load balancer.
autoScaleTaskCount(_props)
public autoScaleTaskCount(_props: EnableScalingProps): ScalableTaskCount
Parameters
- _props
Enable
Scaling Props
Returns
Overridden method to throw error as autoScaleTaskCount
is not supported for external service.
enableCloudMap(_options)
public enableCloudMap(_options: CloudMapOptions): Service
Parameters
- _options
Cloud
Map Options
Returns
Overridden method to throw error as enableCloudMap
is not supported for external service.
enableDeploymentAlarms(alarmNames, options?)
public enableDeploymentAlarms(alarmNames: string[], options?: DeploymentAlarmOptions): void
Parameters
- alarmNames
string[]
- options
Deployment
Alarm Options
Enable Deployment Alarms which take advantage of arbitrary alarms and configure them after service initialization.
If you have already enabled deployment alarms, this function can be used to tell ECS about additional alarms that should interrupt a deployment.
New alarms specified in subsequent calls of this function will be appended to the existing list of alarms.
The same Alarm Behavior must be used on all deployment alarms. If you specify different AlarmBehavior values in multiple calls to this function, or the Alarm Behavior used here doesn't match the one used in the service constructor, an error will be thrown.
If the alarm's metric references the service, you cannot pass Alarm.alarmName
here. That will cause a circular
dependency between the service and its deployment alarm. See this package's README for options to alarm on service
metrics, and avoid this circular dependency.
enableServiceConnect(config?)
public enableServiceConnect(config?: ServiceConnectProps): void
Parameters
- config
Service
Connect Props
Enable Service Connect on this service.
loadBalancerTarget(_options)
public loadBalancerTarget(_options: LoadBalancerTargetOptions): IEcsLoadBalancerTarget
Parameters
- _options
Load
Balancer Target Options
Returns
Overridden method to throw error as loadBalancerTarget
is not supported for external service.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
This method returns the specified CloudWatch metric name for this service.
metricCpuUtilization(props?)
public metricCpuUtilization(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
This method returns the CloudWatch metric for this service's CPU utilization.
metricMemoryUtilization(props?)
public metricMemoryUtilization(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
This method returns the CloudWatch metric for this service's memory utilization.
registerLoadBalancerTargets(..._targets)
public registerLoadBalancerTargets(..._targets: EcsTarget[]): void
Parameters
- _targets
Ecs
Target
Overridden method to throw error as registerLoadBalancerTargets
is not supported for external service.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
protected configureAwsVpcNetworkingWithSecurityGroups(_vpc, _assignPublicIp?, _vpcSubnets?, _securityGroups?)
protected configureAwsVpcNetworkingWithSecurityGroups(_vpc: IVpc, _assignPublicIp?: boolean, _vpcSubnets?: SubnetSelection, _securityGroups?: ISecurityGroup[]): void
Parameters
- _vpc
IVpc
- _assignPublicIp
boolean
- _vpcSubnets
Subnet
Selection - _securityGroups
ISecurity
Group []
Overridden method to throw error as configureAwsVpcNetworkingWithSecurityGroups
is not supported for external service.
static fromExternalServiceArn(scope, id, externalServiceArn)
public static fromExternalServiceArn(scope: Construct, id: string, externalServiceArn: string): IExternalService
Parameters
- scope
Construct
- id
string
- externalServiceArn
string
Returns
Imports from the specified service ARN.
static fromExternalServiceAttributes(scope, id, attrs)
public static fromExternalServiceAttributes(scope: Construct, id: string, attrs: ExternalServiceAttributes): IBaseService
Parameters
- scope
Construct
- id
string
- attrs
External
Service Attributes
Returns
Imports from the specified service attributes.