---
title: "How To Connect A Two EC2 Instances Data Transfer Using AWS CLI Without AWS EFS"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/post/how-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs
---

![Blog post image for How To Connect A Two EC2 Instances Data Transfer Using AWS CLI Without AWS EFS - In this post, I will show you how to transfer data between two EC2 instances using AWS CLI, without AWS EFS.](/_astro/hero.WG5UXtzN_xtBlP.webp)

[Home](/)›[Blog](/blog)›[All Categories](/blog/categories)›[AWS](/blog/categories/aws)

Blog

[Prev in AWSHow To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUI](/blog/post/how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui)[Next in AWSHow To Connect A Two EC2 Instances Database and Files Transfer Using AWS CLI](/blog/post/how-to-connect-a-two-ec2-instances-database-and-files-transfer-using-aws-cli)

[AWS](/blog/categories/aws)[EC2](/blog/categories/ec2)[S3](/blog/categories/s3)[Data Transfer](/blog/categories/data-transfer)[AWS CLI](/blog/categories/aws-cli)

# How To Connect A Two EC2 Instances Data Transfer Using AWS CLI Without AWS EFS

[Mohammad Abu Mattar](/authors/mohammad-abu-mattar)Published: 11 Nov 202208 Mins read14 Mins listen

[Markdown for AI(opens in a new tab)](/post/how-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

TL;DR

In this post, I will show you how to transfer data between two EC2 instances using AWS CLI, without AWS EFS.

Series

[AWS EC2 Interconnection](/series/aws-ec2-interconnection)1/2

[NextHow To Connect A Two EC2 Instances Database and Files Transfer Using AWS CLI](/blog/post/how-to-connect-a-two-ec2-instances-database-and-files-transfer-using-aws-cli)

All posts in this series (2)

Blog2

1.  [How To Connect A Two EC2 Instances Data Transfer Using AWS CLI Without AWS EFSYou are here](/blog/post/how-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs)
2.  [How To Connect A Two EC2 Instances Database and Files Transfer Using AWS CLI](/blog/post/how-to-connect-a-two-ec2-instances-database-and-files-transfer-using-aws-cli)

### How To Connect A Two EC2 Instances Data Transfer Using AWS CLI Without AWS EFS

Contents

[Introduction](#introduction)[Prerequisites](#prerequisites)[Create a VPC](#create-a-vpc)[Step 1: create a VPC](#step-1-create-a-vpc)[Step 2: modify your custom VPC and enable DNS hostname support and DNS support](#step-2-modify-your-custom-vpc-and-enable-dns-hostname-support-and-dns-support)[Step 3: create a public subnet](#step-3-create-a-public-subnet)[Step 4: enable auto-assign public IP on the subnet](#step-4-enable-auto-assign-public-ip-on-the-subnet)[Step 5: create an Internet Gateway](#step-5-create-an-internet-gateway)[Step 6: attach the Internet Gateway to the VPC](#step-6-attach-the-internet-gateway-to-the-vpc)[Step 7: create a route table](#step-7-create-a-route-table)[Step 8: Create a custom route table association](#step-8-create-a-custom-route-table-association)[Step 9: associate the subnet with the route table, making it a public subnet](#step-9-associate-the-subnet-with-the-route-table-making-it-a-public-subnet)[Step 10: create a security group](#step-10-create-a-security-group)[Step 11: Add a rule to the security group](#step-11-add-a-rule-to-the-security-group)[Create an S3 bucket](#create-an-s3-bucket)[Step 1: create an S3 bucket](#step-1-create-an-s3-bucket)[Create two EC2 instances](#create-two-ec2-instances)[Step 1: get the latest AMI ID](#step-1-get-the-latest-ami-id)[Step 2: create a key pair](#step-2-create-a-key-pair)[Step 3: create a user data script](#step-3-create-a-user-data-script)[Step 4: create the two EC2 instances](#step-4-create-the-two-ec2-instances)[Step 5: Check the status of the EC2 instances](#step-5-check-the-status-of-the-ec2-instances)[Conclusion](#conclusion)[Resources](#resources)

## [Introduction](#introduction)

In this post, I will show you how to transfer data between two EC2 instances using AWS CLI, without AWS EFS.

We will use an AWS S3 bucket as the middleman. We will create an AWS S3 bucket and upload a file to it. Then we will download the file from the AWS S3 bucket to the other EC2 instance.

Why use an S3 bucket to move data between two EC2 instances? Because S3 is a highly available, durable, and scalable object storage service. It is designed to make web-scale computing easier for developers.

There are other ways to transfer data between two EC2 instances. You can use AWS EFS, for example. EFS is a file storage service for use with Amazon EC2 instances in the AWS Cloud, and it provides a simple, scalable, fully managed elastic NFS file system for Linux-based workloads.

## [Prerequisites](#prerequisites)

You need to have:

-   AWS CLI installed and configured
-   IAM user with the following permissions:
    -   AmazonEC2FullAccess
    -   AmazonS3FullAccess
    -   AmazonVPCFullAccess

## [Create a VPC](#create-a-vpc)

### [Step 1: create a VPC](#step-1-create-a-vpc)

To create a VPC, run the following command:

Terminal window

```
1# Create a VPC2AWS_VPC=$(aws ec2 create-vpc \3  --cidr-block 10.0.0.0/16 \4  --query 'Vpc.VpcId' \5  --output text)6
7# Add a name tag to the VPC8aws ec2 create-tags \9  --resources $AWS_VPC \10  --tags Key=Name,Value=aws-vpc
```

Explanation:

-   `aws ec2 create-vpc` - Create a VPC
-   `--cidr-block` - The IPv4 network range for the VPC, in CIDR notation.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 2: modify your custom VPC and enable DNS hostname support and DNS support](#step-2-modify-your-custom-vpc-and-enable-dns-hostname-support-and-dns-support)

To modify your custom VPC and enable DNS hostname support and DNS support, run the following command:

Terminal window

```
1# Enable DNS hostnames2aws ec2 modify-vpc-attribute \3  --vpc-id $AWS_VPC \4  --enable-dns-hostnames "{\"Value\":true}"5
6# Enable DNS support7aws ec2 modify-vpc-attribute \8  --vpc-id $AWS_VPC \9  --enable-dns-support "{\"Value\":true}"
```

Explanation:

-   `aws ec2 modify-vpc-attribute` - Modifies the specified attribute of the specified VPC.
-   `--vpc-id` - The ID of the VPC.
-   `--enable-dns-hostnames` - Indicates whether the instances launched in the VPC get DNS hostnames.
-   `--enable-dns-support` - Indicates whether DNS resolution is supported for the VPC.

### [Step 3: create a public subnet](#step-3-create-a-public-subnet)

To create a public subnet, run the following command:

Terminal window

```
1# Create a public subnet2AWS_PUBLIC_SUBNET=$(aws ec2 create-subnet \3  --vpc-id $AWS_VPC \4  --cidr-block 10.0.1.0/24 \5  --query 'Subnet.SubnetId' \6  --output text)7
8# Add a name tag to the public subnet9aws ec2 create-tags \10  --resources $AWS_PUBLIC_SUBNET \11  --tags Key=Name,Value=aws-public-subnet
```

Explanation:

-   `aws ec2 create-subnet` - Creates a subnet in an existing VPC.
-   `--vpc-id` - The ID of the VPC.
-   `--cidr-block` - The IPv4 network range for the subnet, in CIDR notation.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 4: enable auto-assign public IP on the subnet](#step-4-enable-auto-assign-public-ip-on-the-subnet)

To enable auto-assign public IP on the subnet, run the following command:

Terminal window

```
1# Enable auto-assign public IP on the subnet2aws ec2 modify-subnet-attribute \3  --subnet-id $AWS_PUBLIC_SUBNET \4  --map-public-ip-on-launch
```

Explanation:

-   `aws ec2 modify-subnet-attribute` - Modifies a subnet attribute.
-   `--subnet-id` - The ID of the subnet.
-   `--map-public-ip-on-launch` - Specify true to indicate that network interfaces created in the specified subnet should be assigned a public IPv4 address.

### [Step 5: create an Internet Gateway](#step-5-create-an-internet-gateway)

To create an Internet Gateway, run the following command:

Terminal window

```
1# Create an Internet Gateway2AWS_INTERNET_GATEWAY=$(aws ec2 create-internet-gateway \3  --query 'InternetGateway.InternetGatewayId' \4  --output text)5
6# Add a name tag to the Internet Gateway7aws ec2 create-tags \8  --resources $AWS_INTERNET_GATEWAY \9  --tags Key=Name,Value=aws-internet-gateway
```

Explanation:

-   `aws ec2 create-internet-gateway` - Creates an Internet gateway for use with a VPC.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 6: attach the Internet Gateway to the VPC](#step-6-attach-the-internet-gateway-to-the-vpc)

To attach the Internet Gateway to the VPC, run the following command:

Terminal window

```
1# Attach the Internet Gateway to the VPC2aws ec2 attach-internet-gateway \3  --internet-gateway-id $AWS_INTERNET_GATEWAY \4  --vpc-id $AWS_VPC
```

Explanation:

-   `aws ec2 attach-internet-gateway` - Attaches an Internet gateway to a VPC, enabling connectivity between the Internet and the VPC.
-   `--internet-gateway-id` - The ID of the Internet gateway.
-   `--vpc-id` - The ID of the VPC.

### [Step 7: create a route table](#step-7-create-a-route-table)

To create a route table, run the following command:

Terminal window

```
1# Create a route table2AWS_ROUTE_TABLE=$(aws ec2 create-route-table \3  --vpc-id $AWS_VPC \4  --query 'RouteTable.RouteTableId' \5  --output text)6
7# Add a name tag to the route table8aws ec2 create-tags \9  --resources $AWS_ROUTE_TABLE \10  --tags Key=Name,Value=aws-route-table
```

Explanation:

-   `aws ec2 create-route-table` - Creates a route table for the specified VPC.
-   `--vpc-id` - The ID of the VPC.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 8: Create a custom route table association](#step-8-create-a-custom-route-table-association)

To create a custom route table association, run the following command:

Terminal window

```
1# Create a custom route table association2aws ec2 associate-route-table \3  --subnet-id $AWS_PUBLIC_SUBNET \4  --route-table-id $AWS_ROUTE_TABLE
```

Explanation:

-   `aws ec2 associate-route-table` - Associates a subnet with a route table.
-   `--subnet-id` - The ID of the subnet.
-   `--route-table-id` - The ID of the route table.

### [Step 9: associate the subnet with the route table, making it a public subnet](#step-9-associate-the-subnet-with-the-route-table-making-it-a-public-subnet)

To associate the subnet with the route table, making it a public subnet, run the following command:

Terminal window

```
1# Associate the subnet with route table, making it a public subnet2aws ec2 create-route \3  --route-table-id $AWS_ROUTE_TABLE \4  --destination-cidr-block 0.0.0.0/0 \5  --gateway-id $AWS_INTERNET_GATEWAY
```

Explanation:

-   `aws ec2 create-route` - Creates a route in a route table within a VPC.
-   `--route-table-id` - The ID of the route table for the route.
-   `--destination-cidr-block` - The IPv4 CIDR address block used for the destination match.
-   `--gateway-id` - The ID of an Internet gateway or virtual private gateway attached to your VPC.

### [Step 10: create a security group](#step-10-create-a-security-group)

To create a security group, run the following command:

Terminal window

```
1# Create a security group2AWS_SECURITY_GROUP=$(aws ec2 create-security-group \3  --group-name aws-security-group \4  --description "AWS Security Group" \5  --vpc-id $AWS_VPC \6  --query 'GroupId' \7  --output text)8
9# Add a name tag to the security group10aws ec2 create-tags \11  --resources $AWS_SECURITY_GROUP \12  --tags Key=Name,Value=aws-security-group
```

Explanation:

-   `aws ec2 create-security-group` - Creates a security group.
-   `--group-name` - The name of the security group.
-   `--description` - A description for the security group.
-   `--vpc-id` - The ID of the VPC.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to apply to the resource.

### [Step 11: Add a rule to the security group](#step-11-add-a-rule-to-the-security-group)

To add a rule to the security group, run the following command:

Terminal window

```
1# Add a rule to the security group2
3# Add SSH rule4aws ec2 authorize-security-group-ingress \5--group-id $AWS_SECURITY_GROUP \6--protocol tcp \7--port 22 \8--cidr 0.0.0.0/0 \9--output text10
11# Add HTTP rule12aws ec2 authorize-security-group-ingress \13--group-id $AWS_SECURITY_GROUP \14--protocol tcp \15--port 80 \16--cidr 0.0.0.0/0 \17--output text18
19# Add HTTPS rule20aws ec2 authorize-security-group-ingress \21--group-id $AWS_SECURITY_GROUP \22--protocol tcp \23--port 443 \24--cidr 0.0.0.0/0 \25--output text
```

Explanation:

-   `aws ec2 authorize-security-group-ingress` - Adds one or more ingress rules to a security group.
-   `--group-id` - The ID of the security group.
-   `--protocol` - The IP protocol name or number.
-   `--port` - The port number.
-   `--cidr` - The IPv4 CIDR range.
-   `--output` - The output format of the command.

## [Create an S3 bucket](#create-an-s3-bucket)

### [Step 1: create an S3 bucket](#step-1-create-an-s3-bucket)

To create an S3 bucket, run the following command:

Terminal window

```
1AWS_S3_BUCKET_NAME=aws-s3-bucket-$(date +%s)2# Create an S3 bucket3aws s3 mb s3://$AWS_S3_BUCKET_NAME
```

Explanation:

-   `aws s3 mb` - Creates an S3 bucket.
-   `s3://$AWS_S3_BUCKET_NAME` - The name of the bucket to create.

## [Create two EC2 instances](#create-two-ec2-instances)

### [Step 1: get the latest AMI ID](#step-1-get-the-latest-ami-id)

To get the latest AMI ID, run the following command:

Terminal window

```
1# Get the latest AMI ID2AWS_AMI=$(aws ec2 describe-images \3  --owners 'amazon' \4  --filters 'Name=name,Values=amzn2-ami-hvm-2.0.*' \5  'Name=state,Values=available' \6  --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \7  --output 'text')
```

Explanation:

-   `aws ec2 describe-images` - Describes one or more of the images (AMIs, AKIs, and ARIs) available to you.
-   `--owners` - Filters the images by the owner.
-   `--filters` - The filters to apply to the images.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.

### [Step 2: create a key pair](#step-2-create-a-key-pair)

To create a key pair, run the following command:

Terminal window

```
1# Create a key pair2aws ec2 create-key-pair \3--key-name aws-key-pair \4--query 'KeyMaterial' \5--output text > aws-key-pair.pem6
7# Change the permission of the key pair8chmod 400 aws-key-pair.pem
```

Explanation:

-   `aws ec2 create-key-pair` - Creates a 2048-bit RSA key pair with the specified name.
-   `--key-name` - The name for the key pair.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `chmod 400 aws-key-pair.pem` - Changes the permission of the key pair, making it read-only.

### [Step 3: create a user data script](#step-3-create-a-user-data-script)

To create a user data script that uses `cron` to run a sync script every minute, syncing to and from the S3 bucket, run the following command:

```
1# Create a user data script2cat <<EOF > user-data.sh3#!/bin/bash4
5# Update the system6yum update -y7
8# Install Apache9sudo yum install httpd -y10sudo systemctl start httpd11sudo systemctl enable httpd12
13# Create a cron job14chmod 600 /etc/crontab15
16# Create a script to sync from and to the S3 bucket17cat <<EOT1 > /root/sync.sh18#!/bin/bash19
20# Sync from var/www/html to S3 bucket21cd /var/www/html22aws s3 sync . s3://$AWS_S3_BUCKET_NAME23
24# Sync from S3 bucket to var/www/html25cd /var/www/html26aws s3 sync s3://$AWS_S3_BUCKET_NAME .27EOT128
29# Make the script executable30chmod +x /root/sync.sh31
32# Add the script to the cron job33echo "* * * * * root /root/sync.sh" >> /etc/crontab34
35# Create script that creates a random files36cat <<EOF2 > /root/create-random-files.sh37#!/bin/bash38
39# Create a random file40cd /var/www/html41RANDOM_FILE_NAME=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)42touch random-file-$RANDOM_FILE_NAME.txt43EOF244
45# Make the script executable46chmod +x /root/create-random-files.sh47
48# Create a cron job that runs the script every 2 minutes49echo "*/2 * * * * root /root/create-random-files.sh" >> /etc/crontab50
51# Restart the cron service52systemctl restart crond53EOF
```

Explanation:

-   `cat <<EOF > user-data.sh` - Creates a file named `user-data.sh` and writes the following lines to it.
-   `yum update -y` - Updates the system.
-   `sudo yum install httpd -y` - Installs Apache.
-   `sudo systemctl start httpd` - Starts Apache.
-   `sudo systemctl enable httpd` - Enables Apache.
-   `chmod 600 /etc/crontab` - Changes the permission of the `crontab` file, so only its owner can read and write it.
-   `cat <<EOT1 > /root/sync.sh` - Creates a file named `sync.sh` and writes the following lines to it.
-   `aws s3 sync . s3://$AWS_S3_BUCKET_NAME` - Syncs the files from the current directory to the S3 bucket.
-   `aws s3 sync s3://$AWS_S3_BUCKET_NAME .` - Syncs the files from the S3 bucket to the current directory.
-   `chmod +x /root/sync.sh` - Makes the `sync.sh` script executable.
-   `echo "* * * * * root /root/sync.sh" >> /etc/crontab` - Adds the `sync.sh` script to the `crontab` file.
-   `cat <<EOF2 > /root/create-random-files.sh` - Creates a file named `create-random-files.sh` and writes the following lines to it.
-   `cd /var/www/html` - Changes the current directory to `/var/www/html`.
-   `RANDOM_FILE_NAME=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)` - Creates a random file name.
-   `touch random-file-$RANDOM_FILE_NAME.txt` - Creates a random file.
-   `chmod +x /root/create-random-files.sh` - Makes the `create-random-files.sh` script executable.
-   `echo "*/2 * * * * root /root/create-random-files.sh" >> /etc/crontab` - Adds the `create-random-files.sh` script to the `crontab` file.
-   `systemctl restart crond` - Restarts the `crond` service.

### [Step 4: create the two EC2 instances](#step-4-create-the-two-ec2-instances)

To create two EC2 instances, run the following command:

Terminal window

```
1# Create two EC2 instances2AWS_EC2_INSTANCE_1=$(aws ec2 run-instances \3--image-id $AWS_AMI \4--instance-type t2.micro \5--key-name aws-key-pair \6--monitoring "Enabled=false" \7--security-group-ids $AWS_SECURITY_GROUP \8--subnet-id $AWS_PUBLIC_SUBNET \9--user-data file://user-data.sh \10--query 'Instances[0].InstanceId' \11--output text)12
13AWS_EC2_INSTANCE_2=$(aws ec2 run-instances \14--image-id $AWS_AMI \15--instance-type t2.micro \16--key-name aws-key-pair \17--monitoring "Enabled=false" \18--security-group-ids $AWS_SECURITY_GROUP \19--subnet-id $AWS_PUBLIC_SUBNET \20--user-data file://user-data.sh \21--query 'Instances[0].InstanceId' \22--output text)23
24# Add a tag to the instances25aws ec2 create-tags \26--resources $AWS_EC2_INSTANCE_1 \27--tags Key=Name,Value=ec2-instance-128
29aws ec2 create-tags \30--resources $AWS_EC2_INSTANCE_2 \31--tags Key=Name,Value=ec2-instance-2
```

Explanation:

-   `aws ec2 run-instances` - Launches the specified number of instances using an AMI for which you have permissions.
-   `--image-id` - The ID of the AMI.
-   `--instance-type` - The instance type.
-   `--key-name` - The name of the key pair.
-   `--monitoring` - Enables detailed monitoring.
-   `--security-group-ids` - The IDs of the security groups.
-   `--subnet-id` - The ID of the subnet in which to launch the instance.
-   `--user-data` - The user data to make available to the instance.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.
-   `aws ec2 create-tags` - Adds or overwrites one or more tags for the specified resources or resource types.
-   `--resources` - The IDs of the resources.
-   `--tags` - The tags to add or overwrite for the specified resources.

### [Step 5: Check the status of the EC2 instances](#step-5-check-the-status-of-the-ec2-instances)

To check the status of the EC2 instances, run the following command:

Terminal window

```
1# Check the status of the EC2 instances2aws ec2 describe-instances \3--instance-ids $AWS_EC2_INSTANCE_1 $AWS_EC2_INSTANCE_2 \4--query 'Reservations[*].Instances[*].[InstanceId,State.Name,PublicIpAddress]' \5--output table
```

Explanation:

-   `aws ec2 describe-instances` - Describes one or more of your instances.
-   `--instance-ids` - The IDs of the instances.
-   `--query` - The JMESPath query that is applied to the output.
-   `--output` - The output format of the command.

## [Conclusion](#conclusion)

In this tutorial, you learned how to move data between two EC2 instances without AWS EFS. You created a VPC, a public subnet, and a security group. You created an S3 bucket and two EC2 instances. And you set up a cron job that syncs the S3 bucket to the Apache directory and vice versa.

## [Resources](#resources)

-   [Amazon S3 User Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)
-   [Amazon EC2 User Guide for Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html)
-   [Amazon VPC User Guide](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html)
-   [AWS Command Line Interface (CLI) User Guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)
-   [AWS CLI Command Reference - s3 sync](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/sync.html)
-   [AWS CLI Command Reference - ec2](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/index.html)
-   [AWS Identity and Access Management (IAM) User Guide](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)
-   [Scheduling Tasks with Cron](https://www.man7.org/linux/man-pages/man5/crontab.5.html)
-   [User data and shell scripts for EC2 instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html)
-   [Creating an S3 bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)
-   [Working with Amazon S3 Buckets](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingBucket.html)
-   [Security groups for your VPC](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html)
-   [Tutorial: Installing a LAMP Web Server on Amazon Linux 2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-lamp-amazon-linux-2.html) (Relevant for Apache setup)
-   [Transferring data to and from Amazon S3](https://aws.amazon.com/s3/transfer-data/)

Was this useful?

## Tags

[#AWS S3 Sync](/blog/tags/aws-s3-sync)[#EC2 Data Transfer](/blog/tags/ec2-data-transfer)[#AWS CLI Automation](/blog/tags/aws-cli-automation)[#VPC Setup](/blog/tags/vpc-setup)[#S3 Bucket](/blog/tags/s3-bucket)[#Cron Job](/blog/tags/cron-job)[#Linux Server](/blog/tags/linux-server)[#Cloud Storage](/blog/tags/cloud-storage)

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=How%20To%20Connect%20A%20Two%20EC2%20Instances%20Data%20Transfer%20Using%20AWS%20CLI%20Without%20AWS%20EFS&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs&title=How%20To%20Connect%20A%20Two%20EC2%20Instances%20Data%20Transfer%20Using%20AWS%20CLI%20Without%20AWS%20EFS&summary=In%20this%20post%2C%20I%20will%20show%20you%20how%20to%20transfer%20data%20between%20two%20EC2%20instances%20using%20AWS%20CLI%2C%20without%20AWS%20EFS.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=How%20To%20Connect%20A%20Two%20EC2%20Instances%20Data%20Transfer%20Using%20AWS%20CLI%20Without%20AWS%20EFS%20https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs&text=How%20To%20Connect%20A%20Two%20EC2%20Instances%20Data%20Transfer%20Using%20AWS%20CLI%20Without%20AWS%20EFS "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs&title=How%20To%20Connect%20A%20Two%20EC2%20Instances%20Data%20Transfer%20Using%20AWS%20CLI%20Without%20AWS%20EFS "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs&t=How%20To%20Connect%20A%20Two%20EC2%20Instances%20Data%20Transfer%20Using%20AWS%20CLI%20Without%20AWS%20EFS "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs&media=&description=In%20this%20post%2C%20I%20will%20show%20you%20how%20to%20transfer%20data%20between%20two%20EC2%20instances%20using%20AWS%20CLI%2C%20without%20AWS%20EFS. "Share on Pinterest")[Email](<mailto:?subject=How%20To%20Connect%20A%20Two%20EC2%20Instances%20Data%20Transfer%20Using%20AWS%20CLI%20Without%20AWS%20EFS&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs>)

## Comments

## You might also enjoy

More posts on similar topics

[![How To Connect A Two EC2 Instances Database and Files Transfer Using AWS CLI](/_astro/hero.839lq2GB_1XSap0.webp)](/blog/post/how-to-connect-a-two-ec2-instances-database-and-files-transfer-using-aws-cli)

## [How To Connect A Two EC2 Instances Database and Files Transfer Using AWS CLI](/blog/post/how-to-connect-a-two-ec2-instances-database-and-files-transfer-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [EBS](/blog/categories/ebs)
-   [EFS](/blog/categories/efs)
-   [Database](/blog/categories/database)
-   [Networking](/blog/categories/networking)

Introduction In this post, I will show you how to share a database and files between two EC2 instances using AWS CLI. I will use AWS CLI to create a VPC, EC2 instances, EBS, EFS, and security grou

[#AWS CLI](/blog/tags/aws-cli)[#EC2 Instance Communication](/blog/tags/ec2-instance-communication)[#EBS Volume](/blog/tags/ebs-volume)+7 tags

[read more](/blog/post/how-to-connect-a-two-ec2-instances-database-and-files-transfer-using-aws-cli)

[![How To Create a AWS S3 Bucket Using AWS CLI](/_astro/hero.CDw8keBv_tv9MO.webp)](/blog/post/how-to-create-a-aws-s3-bucket-using-aws-cli)

## [How To Create a AWS S3 Bucket Using AWS CLI](/blog/post/how-to-create-a-aws-s3-bucket-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [S3](/blog/categories/s3)
-   [AWS CLI](/blog/categories/aws-cli)
-   [Cloud Storage](/blog/categories/cloud-storage)

Introduction In this post, I will show you how to create an AWS S3 bucket using AWS CLI. Prerequisites You need to have:AWS CLI installed and configured AWS S3 bucket nameAWS S3 bu

[#AWS S3 Bucket](/blog/tags/aws-s3-bucket)[#AWS CLI Commands](/blog/tags/aws-cli-commands)[#S3 Management](/blog/tags/s3-management)+3 tags

[read more](/blog/post/how-to-create-a-aws-s3-bucket-using-aws-cli)

[![How To Create An AWS EC2 Instance Using AWS CLI](/_astro/hero.Dh2x9Phr_14dc4A.webp)](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)

## [How To Create An AWS EC2 Instance Using AWS CLI](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [VPC](/blog/categories/vpc)
-   [AWS CLI](/blog/categories/aws-cli)
-   [WordPress](/blog/categories/wordpress)
-   [Linux](/blog/categories/linux)

Introduction In this tutorial we will create an AWS EC2 instance with the AWS CLI. We will build the network around it first, then launch the instance with a user data script that installs the Apa

[#AWS CLI EC2](/blog/tags/aws-cli-ec2)[#AWS CLI VPC](/blog/tags/aws-cli-vpc)[#VPC Configuration](/blog/tags/vpc-configuration)+8 tags

[read more](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)

[![How To Setup Bastion Host on AWS using AWS CLI](/_astro/hero.DGhoBA0r_KL9IM.webp)](/blog/post/how-to-setup-bastion-host-on-aws-using-aws-cli)

## [How To Setup Bastion Host on AWS using AWS CLI](/blog/post/how-to-setup-bastion-host-on-aws-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [AWS CLI](/blog/categories/aws-cli)
-   [Security](/blog/categories/security)
-   [Networking](/blog/categories/networking)
-   [DevOps](/blog/categories/devops)

Introduction Security is the top priority for any infrastructure and application, and that's why a Bastion host is a must-have in your infrastructure if you want to secure your remote connections.

[#AWS Bastion Host](/blog/tags/aws-bastion-host)[#AWS CLI](/blog/tags/aws-cli)[#VPC Setup](/blog/tags/vpc-setup)+7 tags

[read more](/blog/post/how-to-setup-bastion-host-on-aws-using-aws-cli)

[![How to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO](/_astro/hero.BbyjrsxP_xhG8d.webp)](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)

## [How to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [RDS](/blog/categories/rds)
-   [EC2](/blog/categories/ec2)
-   [PHP](/blog/categories/php)
-   [MySQL](/blog/categories/mysql)
-   [Database](/blog/categories/database)

Introduction In this post, we will learn how to connect an AWS RDS MySQL database to an EC2 instance with PHP, using PDO. PrerequisitesAWS Account EC2 Instance Amazon Linux 2 RDS MySQL

[#AWS RDS MySQL](/blog/tags/aws-rds-mysql)[#EC2 PHP PDO](/blog/tags/ec2-php-pdo)[#Database Connection](/blog/tags/database-connection)+5 tags

[read more](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)

[![How to Install Jenkins on AWS EC2 Instance](/_astro/hero.BzqOEmzv_YuUyx.webp)](/blog/post/install-jenkins-on-aws-ec2-instance)

## [How to Install Jenkins on AWS EC2 Instance](/blog/post/install-jenkins-on-aws-ec2-instance)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [Jenkins](/blog/categories/jenkins)
-   [EC2](/blog/categories/ec2)
-   [DevOps](/blog/categories/devops)
-   [CI/CD](/blog/categories/cicd)

Introduction In this post, I will show you how to create an EC2 instance on AWS and install Jenkins on it. PrerequisitesAWS CLI installed and configured IAM user with the following permi

[#Jenkins Installation](/blog/tags/jenkins-installation)[#AWS EC2 Setup](/blog/tags/aws-ec2-setup)[#Linux Server](/blog/tags/linux-server)+4 tags

[read more](/blog/post/install-jenkins-on-aws-ec2-instance)

6 related posts
