Cameleer

AWS EC2 component

The aws2-ec2 component starts, stops, creates, terminates, tags and describes Amazon EC2 instances.

Scheme: aws2-ec2: · Crate: cameleer-cloud · Cargo feature: cloud · Consumer: no · Producer: yes · Apache Camel: AWS Elastic Compute Cloud (EC2)

When to use it

  • Stop development instances every evening and start them in the morning.
  • Launch worker instances when a queue grows, and terminate them afterwards.
  • Tag instances or report their state from an operations route.

URI format

text
aws2-ec2://label?operation=...[&options]

Example

Stop the development instances once a day (the timer fires at start and then every 24 hours):

yaml example: aws2-ec2-stop-dev-instances
- route:
    id: stop-dev-instances
    from:
      uri: "timer:stop-dev?period=86400000"
      steps:
        - setHeader:
            name: CamelAwsEC2InstancesIds
            constant: "{{env:DEV_INSTANCE_IDS:i-0123456789abcdef0}}"
        - to: "aws2-ec2://ops?region={{env:AWS_REGION:us-east-1}}&operation=stopInstances"
        - log: "state changes: ${body}"

CamelAwsEC2InstancesIds takes a list or comma separated ids. The body after the call is the list of state changes {instanceId, previousState, currentState}.

Rust DSL

rust
ctx.add_routes(|b| {
    b.from("timer:stop-dev?period=86400000")
        .set_header("CamelAwsEC2InstancesIds", constant("{{env:DEV_INSTANCE_IDS:i-0123456789abcdef0}}"))
        .to("aws2-ec2://ops?region={{env:AWS_REGION:us-east-1}}&operation=stopInstances")
        .log("state changes: ${body}");
})?;

Options

Common AWS options (region, credentials, endpoint override, proxy) are listed in Cloud credentials.

optiondefaultdescription
operationRequired: describeInstances, describeInstancesStatus, createAndRunInstances, startInstances, stopInstances, terminateInstances, rebootInstances, monitorInstances, unmonitorInstances, createTags, deleteTags.

Message headers

headerdirectiondescription
CamelAwsEC2OperationinOverrides operation.
CamelAwsEC2InstancesIdsinInstance ids (list or comma separated).
CamelAwsEC2ImageId, CamelAwsEC2InstanceTypeinAMI and type of createAndRunInstances.
CamelAwsEC2InstanceMinCount, CamelAwsEC2InstanceMaxCountinInstance count (default 1).
CamelAwsEC2InstanceKeyPair, CamelAwsEC2InstanceMonitoring, CamelAwsEC2InstanceKernelId, CamelAwsEC2InstanceEbsOptimizedinLaunch settings.
CamelAwsEC2InstanceSecurityGroupsinSecurity group names or sg- ids.
CamelAwsEC2InstancesClientToken, CamelAwsEC2InstancesPlacement, CamelAwsEC2SubnetIdinIdempotency token, availability zone, subnet.
CamelAwsEC2InstancesTagsinTags (map); for deleteTags a list of keys or a map.

Bodies: lists of instances (instanceId, imageId, instanceType, state, launchTime, privateIpAddress, tags, ...), of state changes or of monitoring states.

Run it with Docker

sh
docker run --rm -e AWS_REGION -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e DEV_INSTANCE_IDS \
  -v "$PWD:/routes:ro" pmsudhi/cameleer run /routes/stop-dev.camel.yaml

Common questions

How do I launch an instance?

Use operation=createAndRunInstances with CamelAwsEC2ImageId and CamelAwsEC2InstanceType (plus subnet, security groups and tags as needed); the body is the list of new instances.

Found a problem?

If something on this page doesn't match what Cameleer does, or you hit a bug while building with it, please help fix it, whether you are a person or a coding agent: open an issue that describes what you saw, then fork the repository, fix it, add or update a test, run cargo test --workspace, and open a pull request. CONTRIBUTING.md explains the ground rules.

Edit this page on GitHub