AWS Elastic Container Service (ECS)
Since Camel 3.1
Only producer is supported
The AWS2 ECS component supports create, delete, describe and list clusters AWS ECS clusters instances.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon ECS. More information is available at Amazon ECS.
URI Format
aws2-ecs://label[?options]
You can append query options to the URI in the following format:
?options=value&option2=value&…
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The AWS Elastic Container Service (ECS) component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The shared configuration of the component. Each endpoint starts from a copy of it and then applies its own options. | ECS2Configuration | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The operation that the producer performs. The CamelAwsECSOperation header replaces this option. Enum values:
| ECS2Operations | ||
Whether the ECS client sends its requests to the URI of the uriEndpointOverride option instead of the AWS endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the producer takes the request from the message body, as the AWS SDK request class of the operation, for example a ListClustersRequest for listClusters. A body of another type fails. If false, the producer builds the request from the headers. | false | boolean | |
The AWS region of the ECS client, as the lowercase region ID, for example eu-west-1 (the value of Region.EU_WEST_1.id()). If not set, the AWS SDK takes the region from its default region provider chain, such as the AWS_REGION environment variable. Enum values:
| String | ||
The URI of the endpoint that the ECS client uses instead of the AWS endpoint of the region, for example http://localhost:4566 for LocalStack. It is used only when overrideEndpoint is true. | String | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Autowired To use a custom software.amazon.awssdk.services.ecs.EcsClient. When this option is set or autowired, the endpoint does not build a client from the credentials, proxy, region, overrideEndpoint, uriEndpointOverride and trustAllCertificates options, and it does not close the client when it stops. | EcsClient | ||
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
The host name of the proxy through which the ECS client sends its requests. The proxy is used only when proxyPort is set too. | String | ||
The port of the proxy through which the ECS client sends its requests. The proxy is used only when proxyHost is set too. | Integer | ||
The protocol of the proxy through which the ECS client sends its requests. It is used only when proxyHost and proxyPort are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with secretKey. It is required unless ecsClient is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. | String | ||
The name of the profile that useProfileCredentialsProvider loads. If not set, the AWS SDK uses its default profile: the one of the AWS_PROFILE environment variable, or else default. | String | ||
The secret access key of the AWS credentials, used together with accessKey. It is required unless ecsClient is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example from assuming an IAM role. It is used only when useSessionCredentials is true, together with accessKey and secretKey. | String | ||
Whether the ECS client accepts any TLS certificate without validating it, for example the self-signed certificate of a test endpoint set with uriEndpointOverride. It applies to every request of the client, not only to an overridden endpoint. | false | boolean | |
Whether the ECS client loads its credentials with the default credentials provider chain of the AWS SDK: system properties, environment variables, the profile files, and the credentials of the container or the EC2 instance. It takes precedence over the other credentials options. | false | boolean | |
Whether the ECS client loads its credentials from a profile of the AWS config and credentials files, the one of profileCredentialsName. It is ignored when useDefaultCredentialsProvider is true. | false | boolean | |
Whether the ECS client uses the temporary credentials made of accessKey, secretKey and sessionToken, for example after assuming an IAM role. If sessionToken is not set, accessKey and secretKey are used without it. It is ignored when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Endpoint Options
The AWS Elastic Container Service (ECS) endpoint is configured using URI syntax:
aws2-ecs:label
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The operation that the producer performs. The CamelAwsECSOperation header replaces this option. Enum values:
| ECS2Operations | ||
Whether the ECS client sends its requests to the URI of the uriEndpointOverride option instead of the AWS endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the producer takes the request from the message body, as the AWS SDK request class of the operation, for example a ListClustersRequest for listClusters. A body of another type fails. If false, the producer builds the request from the headers. | false | boolean | |
The AWS region of the ECS client, as the lowercase region ID, for example eu-west-1 (the value of Region.EU_WEST_1.id()). If not set, the AWS SDK takes the region from its default region provider chain, such as the AWS_REGION environment variable. Enum values:
| String | ||
The URI of the endpoint that the ECS client uses instead of the AWS endpoint of the region, for example http://localhost:4566 for LocalStack. It is used only when overrideEndpoint is true. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Autowired To use a custom software.amazon.awssdk.services.ecs.EcsClient. When this option is set or autowired, the endpoint does not build a client from the credentials, proxy, region, overrideEndpoint, uriEndpointOverride and trustAllCertificates options, and it does not close the client when it stops. | EcsClient | ||
The host name of the proxy through which the ECS client sends its requests. The proxy is used only when proxyPort is set too. | String | ||
The port of the proxy through which the ECS client sends its requests. The proxy is used only when proxyHost is set too. | Integer | ||
The protocol of the proxy through which the ECS client sends its requests. It is used only when proxyHost and proxyPort are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with secretKey. It is required unless ecsClient is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. | String | ||
The name of the profile that useProfileCredentialsProvider loads. If not set, the AWS SDK uses its default profile: the one of the AWS_PROFILE environment variable, or else default. | String | ||
The secret access key of the AWS credentials, used together with accessKey. It is required unless ecsClient is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example from assuming an IAM role. It is used only when useSessionCredentials is true, together with accessKey and secretKey. | String | ||
Whether the ECS client accepts any TLS certificate without validating it, for example the self-signed certificate of a test endpoint set with uriEndpointOverride. It applies to every request of the client, not only to an overridden endpoint. | false | boolean | |
Whether the ECS client loads its credentials with the default credentials provider chain of the AWS SDK: system properties, environment variables, the profile files, and the credentials of the container or the EC2 instance. It takes precedence over the other credentials options. | false | boolean | |
Whether the ECS client loads its credentials from a profile of the AWS config and credentials files, the one of profileCredentialsName. It is ignored when useDefaultCredentialsProvider is true. | false | boolean | |
Whether the ECS client uses the temporary credentials made of accessKey, secretKey and sessionToken, for example after assuming an IAM role. If sessionToken is not set, accessKey and secretKey are used without it. It is ignored when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Message Headers
The AWS Elastic Container Service (ECS) component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAwsECSOperation (producer) Constant: | The operation that the producer performs. It replaces the operation option. | String | |
CamelAwsECSMaxResults (producer) Constant: | The maximum number of clusters that listClusters returns in one page, from 1 to 100. If not set, Amazon ECS returns up to 100. | Integer | |
CamelAwsECSClusterName (producer) Constant: | The short name or the full ARN of the cluster. createCluster takes the name of the new cluster and deleteCluster requires it. If not set, Amazon ECS uses the cluster named default for createCluster and describeCluster. | String | |
CamelAwsECSNextToken (producer) Constant: | The token of the next page of listClusters. The producer reads it to request that page, and sets it from the response, or to null on the last page. | String | |
CamelAwsECSIsTruncated (producer) Constant: | Whether more clusters follow the ones that listClusters returned, that is whether the response has a next token. The producer sets it. | Boolean | |
CamelAwsECSClusterArn (producer) Constant: | The ARN of the cluster that the operation created, described or deleted. The producer sets it. | String |
Message Body
The message body at each side of the AWS Elastic Container Service (ECS) component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Producer input |
| Not used: the operations take their input from headers, such as the name of the cluster in CamelAwsECSClusterName. With pojoRequest=true the request of the AWS SDK for the operation, such as a ListClustersRequest: another body fails.
|
Producer output |
| The response of the AWS SDK for the operation, such as the ListClustersResponse of listClusters, with the token of the next page in a header. describeCluster of a cluster that does not exist does not fail: the response lists it in its failures. |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Required ECS component options
You have to provide the amazonECSClient in the Registry or your accessKey and secretKey to access the Amazon ECS service.
Usage
Static credentials, Default Credential Provider and Profile Credentials Provider
You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true.
The order of evaluation for Default Credentials Provider is the following:
-
Java system properties -
aws.accessKeyIdandaws.secretKey. -
Environment variables -
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. -
Web Identity Token from AWS STS.
-
The shared credentials and config files.
-
Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIis set. -
Amazon EC2 Instance profile credentials.
You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of static, default and profile credentials could be used at the same time.
For more information about this you can look at AWS credentials documentation
Producer Examples
-
listClusters: this operation will list the available clusters in ECS
-
Java
-
XML
-
YAML
from("direct:listClusters")
.to("aws2-ecs://test?ecsClient=#amazonEcsClient&operation=listClusters"); <route>
<from uri="direct:listClusters"/>
<to uri="aws2-ecs://test?ecsClient=#amazonEcsClient&operation=listClusters"/>
</route> - route:
from:
uri: direct:listClusters
steps:
- to:
uri: aws2-ecs://test
parameters:
ecsClient: "#amazonEcsClient"
operation: listClusters Using a POJO as body
Sometimes building an AWS Request can be complex because of multiple options. We introduce the possibility to use a POJO as a body. In AWS ECS there are multiple operations you can submit, as an example for List cluster request, you can do something like:
from("direct:start")
.setBody(ListClustersRequest.builder().maxResults(10).build())
.to("aws2-ecs://test?ecsClient=#amazonEcsClient&operation=listClusters&pojoRequest=true") In this way, you’ll pass the request directly without the need of passing headers and options specifically related to this operation.
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws2-ecs</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.