IAM Programmatic access
In order to access your AWS account from a terminal or system, you can use AWS Access keys and AWS Secret Access keys.
AWS CLI
The AWS Command Line Interface (AWS CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.
The AWS CLI v2 offers several new features including improved installers, new configuration options such as AWS IAM Identity Center (successor to AWS SSO), and various interactive features.
S3
Amazon Simple Storage Service (Amazon S3) is an object storage service that provides a secure and scalable way to store and access data on the cloud. It is designed for storing any kind of data, such as text files, images, videos, backups, and more.
Task-01
- Create AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from AWS Console.
Login in to your AWS account using root user credentials.
Click on your username in the top right corner of the console and select "Security Credentials" from the drop-down menu.
Scroll down and find the Access keys section.
Click on "Create Access Key."
Your access key ID and secret access key will be displayed. Make sure to download the CSV file with your access key information and store it in a secure location.
Task-02
- Setup and install AWS CLI and configure your account credentials.
Install the AWS CLI by following the instructions for your operating system: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
For Windows use this command in the terminal:msiexec.exe /i
https://awscli.amazonaws.com/AWSCLIV2.msi
Finish the installation procedure.
Restart the terminal and use this command to check whether it has been installed. aws --version
You can check the bucket that has been created in Task03 here by using the command as shown in the image.
Task-03
Launch an EC2 instance using the AWS Management Console and connect to it using Secure Shell (SSH).
Create an S3 bucket and upload a file to it using the AWS Management Console.
Access the file from the EC2 instance using the AWS Command Line Interface (AWS CLI).
Log in to the AWS Management Console.
Navigate to the EC2 service and launch an EC2 instance using the console.
S3:
Click on the "Create bucket" button.
Enter a unique name for your bucket, select the region you want to create it in, and then click "Create."
Click on 'Create Bucket'
Once your bucket is created, click on its name to open it.
Click on the "Upload" button to upload a file.
In the "Upload" window, click on the "Add files" button to select the file you want to upload.
I am creating a .txt file in notepad.
Once you've selected your file, click "Next."
next you can set permissions for your file, configure storage class and set metadata.
review the details before clicking on the "Upload" button to upload your file.
Once the upload is complete, you can see the file in your S3 bucket.
Access the file from the EC2 instance using the AWS Command Line Interface (AWS CLI).
Install the AWS CLI in the instance using the link shared in task02.
Once you have installed the AWS CLI, open a terminal and run the command aws configure to configure your account credentials.
Enter your AWS Access Key ID and Secret Access Key.
List the s3 buckets.
Then you can use the aws s3 cp command to copy the file from your S3 bucket to your EC2 instance and view content of file using cat command.
Task-04
Create a snapshot of the EC2 instance and use it to launch a new EC2 instance.
Download a file from the S3 bucket using the AWS CLI.
Verify that the contents of the file are the same on both EC2 instances.
Select Snapshots from the Elastic Block Store in the EC2 dashboard in the Left-Hand column.
Select the EC2 instance that you want to create a snapshot of.
Snapshot created.
Use snapshot to launch a new EC2 instance
In right side, click on Actions and select 'Create image from snapshot'
In the "Create Image from snapshot" window, enter a name and description for the image.
Click on 'create image'.
Once the image is created, go to the "AMIs" section in the EC2 Dashboard.
Check if image is created.
Select the newly created AMI, right-click on it, and select "Launch Instance."
In the "Launch Instance" window, choose the configuration options for the new instance.
Choose the VPC and subnet you want to launch the new instance in.
In the "Add Storage" section, you can choose to modify the storage volumes as per your requirements.
Review the instance details and click "Launch instance" to launch the new instance.
Connect to your new instance using SSH.
here login as the user "ubuntu" rather than the user "root"(replace root by ubuntu in the ssh command)
Download a file from the S3 bucket using the AWS CLI.
aws s3 cp command to download the file from your S3 bucket to your EC2 instance.
Verify that the contents of the file are the same on both EC2 instances.
Here are some commonly used AWS CLI commands for Amazon S3:
aws s3 ls
- This command lists all of the S3 buckets in your AWS account.
aws s3 mb s3://bucket-name
- This command creates a new S3 bucket with the specified name.
aws s3 rb s3://bucket-name
- This command deletes the specified S3 bucket.
aws s3 cp file.txt s3://bucket-name
- This command uploads a file to an S3 bucket.
aws s3 cp s3://bucket-name/file.txt .
- This command downloads a file from an S3 bucket to your local file system.
aws s3 sync local-folder s3://bucket-name
- This command syncs the contents of a local folder with an S3 bucket.
aws s3 ls s3://bucket-name
- This command lists the objects in an S3 bucket.
aws s3 rm s3://bucket-name/file.txt
- This command deletes an object from an S3 bucket.
aws s3 presign s3://bucket-name/file.txt
- This command generates a pre-signed URL for an S3 object, which can be used to grant temporary access to the object.
aws s3api list-buckets
- This command retrieves a list of all S3 buckets in your AWS account, using the S3 API.
Thankyou for reading until here. See you in the next one. Happy Learning!