Contact Free trial Login

Amazon EC2 Connector - Mule 4

Support Category: Select

Amazon EC2 Connector v2.3

Anypoint Connector for Amazon EC2 (Amazon EC2 Connector) provides connectivity to the Amazon Elastic Compute Cloud (Amazon EC2) API, enabling you to interface with Amazon EC2 to launch as many or as few virtual servers as you need, configure security and networking, and manage storage.

Prerequisites

To use Amazon EC2 Connector, you must have the following:

  • AWS Identity and Access Management (IAM) user account credentials

  • Access to EC2 via the AWS cloud

  • Anypoint Studio 7.0 or later

  • A secret access key to IAM

Compatibility

Amazon EC2 connector is compatible with:

Application/Service Version

Mule

4.1.1 and later

Anypoint Studio

7.0 and later

AWS SDK for Java

1.11.611

Java

1.8.0_x

Add the Connector to Your Project

Anypoint Studio provides two ways to add the connector to your Studio project:

  • From the Exchange button in the Studio taskbar

  • From the Mule Palette view

Add the Connector Using Exchange

  1. In Studio, create a Mule project.

  2. Click the Exchange icon (X) in the upper-left of the Studio task bar.

  3. In Exchange, click Login and supply your Anypoint Platform username and password.

  4. In Exchange, search for "ec2".

  5. Select the connector and click Add to project.

  6. Follow the prompts to install the connector.

Add the Connector in Studio

  1. In Studio, create a Mule project.

  2. In the Mule Palette view, click (X) Search in Exchange.

  3. In Add Modules to Project, type "ec2" in the search field.

  4. Click this connector’s name in Available modules.

  5. Click Add.

  6. Click Finish.

Configure a Global Element

To use the Amazon EC2 Connector in your Mule application, configure a global Amazon EC2 element to use with all instances of Amazon EC2 Connector in your project. You can configure the global element using Anypoint Studio’s visual editor, an XML editor, or a standalone editor.

Configure with Studio’s Visual Editor

  1. Click the Global Elements tab at the bottom of the canvas.

  2. In the Global Mule Configuration Elements screen, click Create.

  3. In the Choose Global Type wizard, expand Connector Configuration, select Amazon EC2: Configuration, and click OK.

    Global Element Configuration Wizard
  4. Configure the parameters:

    • Access Key: Alphanumeric text string that uniquely identifies the user who owns the account

    • Secret Key: Key that plays the role of a password

    • Try Default AWS Credentials Provider Chain: Checkbox that controls whether temporary credentials should be used

  5. Set placeholder values in the mule-artifact.properties configuration file in the src/main/resources folder of your project.

    You can either enter your credentials into the global configuration properties or reference a configuration file that contains these values. For simpler maintenance and better reusability of your project, use a configuration file. Keeping these values in a separate file is useful if you need to deploy to different environments, such as production, development, and QA, where your access credentials differ.

  6. Leave the Advanced tab values unchanged.

  7. Click Test Connection to confirm that the parameters of your global configuration are accurate, and that Mule is able to successfully connect to your instance of Amazon EC2.

  8. Click OK to save the global connector configuration.

Configure with the XML Editor or Standalone

In Studio, when you drag the connector from the Mule Palette view to the canvas, Studio automatically populates the XML code and POM file for the connector namespace and schema location.

Alternatively, you can code the connector manually:

  1. Include the Amazon EC2 namespace and schema location in your configuration file.

    Namespace: http://www.mulesoft.org/schema/mule/ec2
    Schema Location: http://www.mulesoft.org/schema/mule/ec2/current/mule-ec2.xsd

    These statements appear in the <mule> block that starts a Mule app:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <mule xmlns:ec2="http://www.mulesoft.org/schema/mule/ec2"
    	xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
    	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
    	xmlns:http="http://www.mulesoft.org/schema/mule/http"
    	xmlns="http://www.mulesoft.org/schema/mule/core"
    	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    	xmlns:spring="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="
    	http://www.mulesoft.org/schema/mule/ee/dw
    	http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
    	http://www.springframework.org/schema/beans
    	http://www.springframework.org/schema/beans/spring-beans-current.xsd
    	http://www.mulesoft.org/schema/mule/core
    	http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    	http://www.mulesoft.org/schema/mule/http
    	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    	http://www.mulesoft.org/schema/mule/ee/core
    	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
    	http://www.mulesoft.org/schema/mule/ec2
    	http://www.mulesoft.org/schema/mule/ec2/current/mule-ec2.xsd">
    	<!-- Put your flows and configuration elements here -->
    </mule>
  2. Create a global Amazon EC2 configuration outside your flows, using the following global configuration code:

    <ec2:config name="Amazon_EC2_configuration" doc:name="Amazon EC2 Configuration" >
    	<ec2:basic-connection
    		accessKey="${amazon.accesskey}"
    		secretKey="${amazon.secretkey}"
    		region="${amazon.region}"
    		sessionToken="{amazon.sessionToken}"/>
    </ec2:config>
  3. Include this XML snippet in your pom.xml file:

    <dependency>
        <groupId>com.mulesoft.connectors</groupId>
        <artifactId>mule-amazon-ec2-connector</artifactId>
        <version>RELEASE</version>
        <classifier>mule-plugin</classifier>
    </dependency>

    Mule converts the RELEASE value to the latest release.

    To obtain the most up-to-date pom.xml file information, access the connector in Anypoint Exchange and click Dependency Snippets.

EC2 Connector Operations

Amazon EC2 Connector supports the following Anypoint Studio operations.

AMIs

Studio Operation Name XML Operation Name
  • Create image

  • Deregister image

  • Describe image attribute

  • Describe images

  • Modify image attribute

  • Reset image attribute

  • CreateImage

  • DeregisterImage

  • DescribeImageAttribute

  • DescribeImages

  • ModifyImageAttribute

  • ResetImageAttribute

Elastic IP Addresses

Studio Operation Name XML Operation Name
  • Allocate address

  • Associate address

  • Describe addresses

  • Describe moving addresses

  • Disassociate address

  • Move address to VPC

  • Release address

  • Restore address to classic

  • AllocateAddress

  • AssociateAddress

  • DescribeAddresses

  • DescribeMovingAddresses

  • DisassociateAddress

  • MoveAddressToVpc

  • ReleaseAddress

  • RestoreAddressToClassic

Elastic Network Interfaces (Amazon VPC)

Studio Operation Name XML Operation Name
  • Assign IPV 6 addresses

  • Assign private IP addresses

  • Attach network interface

  • Create network interface

  • Delete network interface

  • Describe network interface attribute

  • Describe network interfaces

  • Detach network interface

  • Modify network interface attribute

  • Reset network interface attribute

  • Unassign IPV 6 addresses

  • Unassign private IP addresses

  • AssignIpv6Addresses

  • AssignPrivateIpAddresses

  • AttachNetworkInterface

  • CreateNetworkInterface

  • DeleteNetworkInterface

  • DescribeNetworkInterfaceAttribute

  • DescribeNetworkInterfaces

  • DetachNetworkInterface

  • ModifyNetworkInterfaceAttribute

  • ResetNetworkInterfaceAttribute

  • UnassignIpv6Addresses

  • UnassignPrivateIpAddresses

Instances

Studio Operation Name XML Operation Name
  • Associate IAM instance profile

  • Describe IAM instance profile associations

  • Describe instance attribute

  • Describe instances

  • Describe instance Status

  • Disassociate IAM Instance profile

  • Get console output

  • Get console screenshot

  • Get password data

  • Modify instance attribute

  • Monitor instances

  • Reboot instances

  • Replace IAM instance profile association

  • Report instance status

  • Reset instance attribute

  • Run instances

  • Start instances

  • Stop instances

  • Terminate instances

  • Unmonitor instances

  • AssociateIamInstanceProfile

  • DescribeIamInstanceProfileAssociations

  • DescribeInstanceAttribute

  • DescribeInstances

  • DescribeInstanceStatus

  • DisassociateIamInstanceProfile

  • GetConsoleOutput

  • GetConsoleScreenshot

  • GetPasswordData

  • ModifyInstanceAttribute

  • MonitorInstances

  • RebootInstances

  • ReplaceIamInstanceProfileAssociation

  • ReportInstanceStatus

  • ResetInstanceAttribute

  • RunInstances

  • StartInstances

  • StopInstances

  • TerminateInstances

  • UnmonitorInstances

Key Pairs

Studio Operation Name XML Operation Name
  • Create key pair

  • Delete key pair

  • Describe key pairs

  • Import key pair

  • CreateKeyPair

  • DeleteKeyPair

  • DescribeKeyPairs

  • ImportKeyPair

Regions and Availability Zones

Studio Operation Name XML Operation Name
  • Describe availability zones

  • Describe regions

  • DescribeAvailabilityZones

  • DescribeRegions

Security Groups

Studio Operation Name XML Operation Name
  • Authorize security group egress

  • Authorize security group ingress

  • Create security group

  • Delete security group

  • Describe security group references

  • Describe security groups

  • Describe stale security groups

  • Revoke security group egress

  • Revoke security group ingress

  • AuthorizeSecurityGroupEgress

  • AuthorizeSecurityGroupIngress

  • CreateSecurityGroup

  • DeleteSecurityGroup

  • DescribeSecurityGroupReferences

  • DescribeSecurityGroups

  • DescribeStaleSecurityGroups

  • RevokeSecurityGroupEgress

  • RevokeSecurityGroupIngress

Tags

Studio Operation Name XML Operation Name
  • Create tags

  • Delete tags

  • Describe tags

  • CreateTags

  • DeleteTags

  • DescribeTags

Volumes and Snapshots (Amazon EBS)

Studio Operation Name XML Operation Name
  • Attach volume

  • Copy snapshot

  • Create snapshot

  • Create volume

  • Delete snapshot

  • Delete volume

  • Describe snapshot attribute

  • Describe snapshots

  • Describe volume attribute

  • Describe volumes

  • Describe volumes modifications

  • Describe volume status

  • Detach volume

  • Enable volume IO

  • Modify snapshot attribute

  • Modify volume

  • Modify volume attribute

  • Reset snapshot attribute

  • AttachVolume

  • CopySnapshot

  • CreateSnapshot

  • CreateVolume

  • DeleteSnapshot

  • DeleteVolume

  • DescribeSnapshotAttribute

  • DescribeSnapshots

  • DescribeVolumeAttribute

  • DescribeVolumes

  • DescribeVolumesModifications

  • DescribeVolumeStatus

  • DetachVolume

  • EnableVolumeIO

  • ModifySnapshotAttribute

  • ModifyVolume

  • ModifyVolumeAttribute

  • ResetSnapshotAttribute

Connector Namespace and Schema

When designing your application in Studio, the act of dragging the connector from the palette onto the Anypoint Studio canvas should automatically populate the XML code with the connector namespace and schema location.

Namespace: http://www.mulesoft.org/schema/mule/ec2

Schema Location: http://www.mulesoft.org/schema/mule/ec2/current/mule-ec2.xsd

If you are manually coding the Mule application in Studio’s XML editor or other text editor, paste these into the header of your Configuration XML, inside the <mule> tag.

<mule xmlns:ec2="http://www.mulesoft.org/schema/mule/ec2"
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/ee/dw
http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core
http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/ec2
http://www.mulesoft.org/schema/mule/ec2/current/mule-ec2.xsd">

      <!-- here go your global configuration elements and flows -->

</mule>

Using the Connector in a Mavenized Mule App

If you are coding a Mavenized Mule application, this XML snippet must be included in your pom.xml file.

<dependency>
    <groupId>com.mulesoft.connectors</groupId>
    <artifactId>mule-amazon-ec2-connector</artifactId>
    <version>2.3</version>
    <classifier>mule-plugin</classifier>
</dependency>

Mule converts the value in the <version></version> element to the latest version.

Use Cases and Demos

Common use cases for the connector:

  • Create an EBS volume to attach to an instance in the same availability zone

  • Attach an EBS volume to a running or stopped Amazon EC2 instance

  • Restart an Amazon EBS-backed AMI that you’ve previously stopped

  • Stop an Amazon EC2 instance

Create an EBS Volume

This example creates an EBS volume that you can attach to an EC2 instance in the same availability zone:

Creating an EBS volume
  1. Create a new Mule project in Anypoint Studio.

  2. Add the following properties to the mule-artifact.properties file to hold your Amazon EC2 credentials and place it in the project’s src/main/resources directory:

    amazon.accesskey=<Access Key>
    amazon.secretkey=<Secret Key>
    amazon.region=<Region>
    amazon.sessionToken=<Session Token>
  3. Drag the HTTP Listener component to the canvas, and specify the following values:

    • Host: localhost

    • Port: 8081

  4. Drag the Amazon EC2 Connector Create volume operation next to the HTTP Listener component.

  5. Configure the EC2 connector by adding a new Amazon EC2 Global Element.

  6. Click the plus sign next to the Connector Configuration field.

  7. Configure the global element:

    Studio Field Value

    Display Name

    Listener

    Extension Configuration

    If an HTTP Listener configuration doesn’t exist:

    1. Click the plus sign (+) to add a new HTTP Listener configuration.

    2. Provide the following values:

      • Host: localhost

      • Port: 8081

    3. Click OK.

    Path

    /createVolume

  8. Drag the Amazon EC2 Connector Create volume operation next to the HTTP Listener component.

  9. Configure the EC2 connector by adding a new Amazon EC2 global element and click + next to the Connector Configuration field.

  10. Configure the global element as follows:

    Studio Field Description

    Name

    Name by which to reference the connector

    Session Token

    Session token used to validate the temporary security credentials

    Access Key

    Alphanumeric text string that uniquely identifies the user who owns the account

    Secret Key

    Key that acts as a password

    Region Endpoint

    Region to select from the drop-down menu for the Amazon EC2 client

    Your configuration should look like this:

    ec2 global config

    The corresponding XML configuration should be as follows:

    <ec2:config
    	name="Amazon_EC2_configuration"
    	doc:name="Amazon EC2 Configuration" >
    <ec2:basic-connection
    	accessKey="${amazon.accesskey}"
    	secretKey="${amazon.secretkey}"
    	region="${amazon.region}"
    	sessionToken="${amazon.sessionToken}"/>
    </ec2:config>
  11. Click Test Connection to confirm that Mule can connect with the EC2 instance.

  12. If the connection is successful, click OK to save the configurations.

    Otherwise, review or correct any incorrect parameters, then test again.

  13. In the Properties editor, configure the remaining parameters:

    Studio Field Value

    Display Name

    Create Volume (or any other name you prefer)

    Basic Settings

    Extension Configuration

    Amazon_EC2_Configuration (the name you created for the global element)

    General

    Availability Zone

    us-east-1a (or any other availability zone to which you have access)

    Size

    5 (the size of the volume, in gibibytes GiBs)

    Volume Type

    Standard (the default volume type)

    publish message connector props
  14. Verify that your XML looks like this:

    <ec2:create-volume
    	config-ref="Amazon_EC2_configuration"
    	availabilityZone="us-east-1a"
    	doc:name="Create volume"
    	size="5"/>
  15. Add Set Payload after the Amazon EC2 Create Volume operation to send the response to the client in the browser.

  16. Set Value to #[payload.volume.volumeId] to print the volume ID of the EBS volume:

    ec2 create volume payload transformer
  17. Add a Logger component after Set Payload to display the Volume ID that is being transformed by the Set Payload transformer from the Create Volume operation in the Mule Console.

  18. Set the Logger Message to #[payload] and Level to INFO:

    ec2 create volume logger
  19. In Package Explorer, right-click the project and select Run As > Mule Application.

  20. Browse to http://localhost:8081/createVolume.

    You should see the generated Volume ID in the browser and console.

Example Mule App XML Code

Paste this code into your XML Editor to quickly load the flow for this example use case into your Mule app:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ec2="http://www.mulesoft.org/schema/mule/ec2"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
	http://www.mulesoft.org/schema/mule/core/current/mule.xsd
	http://www.mulesoft.org/schema/mule/http
	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
	http://www.mulesoft.org/schema/mule/ec2
	http://www.mulesoft.org/schema/mule/ec2/current/mule-ec2.xsd">
	<http:listener-config
		name="HTTP_Listener_config"
		doc:name="HTTP Listener config" >
		<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>
	<ec2:config
		name="Amazon_EC2_configuration"
		doc:name="Amazon EC2 Configuration" >
		<ec2:basic-connection
			accessKey="${amazon.accesskey}"
			secretKey="${amazon.secretkey}"
			region="USEAST1"
			sessionToken="${amazon.sessionToken}"/>
	</ec2:config>
	<flow name="create-ebs-volume" >
		<http:listener
			config-ref="HTTP_Listener_config"
			path="/createVolume"
			doc:name="Listener" />
		<ec2:create-volume
			config-ref="Amazon_EC2_configuration"
			availabilityZone="us-east-1a"
			doc:name="Create volume"
			size="5"/>
		<set-payload
			value="#[payload.volume.volumeId]"
			doc:name="Set Payload"  />
		<logger
			level="INFO"
			doc:name="Logger"
			message="#[payload]"/>
	</flow>
</mule>