Here are the step-by-step instructions to push files from an EC2 instance to an Amazon S3 bucket. Before you begin, ensure you have the following prerequisites in place:

Prerequisites:

  1. Amazon Web Services (AWS) Account: You should have an AWS account. If you don't have one, you can sign up for a free AWS account.
  2. EC2 Instance: You should have an EC2 instance up and running with the necessary permissions to access your S3 bucket. Ensure your EC2 instance has the AWS Command Line Interface (CLI) installed.
  3. S3 Bucket: You should have an S3 bucket created in your AWS account where you want to push the files.

Step-by-Step Instructions:

  1. Access Your EC2 Instance:
    • Use SSH to connect to your EC2 instance. Replace your-instance-ip with the actual IP address of your EC2 instance and your-key.pem with your private key file.
      ​​​​​​​​ssh -i your-key.pem ec2-user@your-instance-ip
      
  2. Install and Configure AWS CLI:
    • If AWS CLI is not already installed on your EC2 instance, you can install it by running the following commands:
      ​​​​​​​​sudo yum update -y
      ​​​​​​​​sudo yum install aws-cli -y
      
    • Configure AWS CLI with your AWS credentials. Run:
      ​​​​​​​​aws configure
      
      You will be prompted to enter your AWS Access Key ID, Secret Access Key, default region name, and output format. You can find your Access Key ID and Secret Access Key in your AWS account's Security Credentials section.
  3. Push Files to S3 Bucket:
    • To push files from your EC2 instance to your S3 bucket, you can use the aws s3 cp command. Replace source-file with the path to your local file and s3://your-bucket-name/destination-path with the S3 bucket and destination path where you want to store the file. For example:
      ​​​​​​​​aws s3 cp /path/to/local/file.jpg s3://your-bucket-name/folder/
      
      This command will upload file.jpg from your EC2 instance to the specified S3 bucket.
  4. Verify the Upload:
    • You can verify that the file has been successfully uploaded to your S3 bucket by navigating to the AWS S3 Management Console in your AWS account.