H0W TO COPY FILES FROM EC2 TO S3 (Vice Versa) IN LINUX SERVER
Step 1:- Open the AWS Management Console and launch an EC2 Linux Server.
Step 2:- Create an IAM role on behalf of EC2 and assign the "AmazonS3FullAccess" policy.
Step 3:- Now Click on "Action > Security > Modify IAM role" and attach the role to the EC2 Instance
Step 4:- Create a S3 bucket & make sure it has a unique bucket name also create a folder.
Step 5 Create an S3 bucket & make sure it has a unique bucket name also create a folder.
Step 6:- Now connect the EC2 instance directly or the session manager.
Step 7: Now COPY FILES FROM EC2 TO S3
aws s3 ls
#It will display all buckets in s3 buket
mkdir example
#create directory
vi demo.txt
# create a file
pwd
#To Display localpath of file
aws s3 cp /path/to/local-file s3://bucket-name/s3-prefix/
# eg:- aws s3 cp /mydir/file.txt s3://mybucket89012/myfolder/
Here we can see the file has been successfully downloaded in the S3 bucket
Step 8: Copy Files FROM S3 TO EC2
aws s3 cp s3://my-bucket/example.txt local/to/path
aws s3 cp s3://mybucket89012/myfolder/Demo2.txt /mydir
Now here we can see that mydir Demo2.txt has been downloaded. That's it! We have successfully copied or moved files between your Amazon EC2 instance and Amazon S3 using the AWS CLI.