1st Step - Create S3 Bucket
In the AWS management console search S3 and click Create bucket button.
Next, Type the bucket name as ec2-bucket-demo (You can any name globally unique) and keep other settings as default.
Finally, Hit create bucket button.
2nd Step - Create IAM Role for EC2 instance
In the AWS management console search IAM and go to the Roles tab. After that Hit create role button.
Next, select the use case as EC2 and Hit the next button.
Next, the Permission section selects the type as AWS Managed and selects "AmazonS3FullAccess". After that hit the Next button.
Finally, give the name for the IAM role and click create button. After that, you can see your newly created role.
3rd Step - Create EC2 Instance and attached the IAM role for EC2 Instance
You can see your newly created EC2 instance.
Go to an EC2 instance dashboard and click EC2 instance go to actions and Security finally click Modify IAM Role.
Next, Modify the IAM role and click the previously created IAM Role and click Update the IAM role.
4th Step - Connect EC2 Instance and Install AWS CLI
5th Step - Check S3 buckets using AWS CLI and create new file
After that copy created file using AWS CLI to S3.
Use the following command.
aws s3 cp my.txt s3://{{Your-Bucket-Name}}
6th Step - Using crontab to add the S3 copy command
You can add a crontab to automate backups. You can use the below command to open crontab. You can use any terminal editor. Ex - Vim, Nano
7th Step - Check S3 Backup files
Finally, You can see your S3 bucket backup file updated.
Thanks for reading the Article.
References - Check crobjob
Top comments (0)