Access S3 bucket from EC2 Instance using Terraform

Lab Details

  1. This lab walks you through the steps to access the S3 bucket and its objects from EC2 Instance using IAM Role.

  2. Duration: 90 minutes

  3. AWS Region: US East (N. Virginia) us-east-1

Introduction

What is EC2

  • AWS defines it as Elastic Compute Cloud.

  • It’s a virtual environment where “you rent” to have your environment created, without purchasing. 

  • Amazon refers to these virtual machines as Instances.

  • Preconfigured templates can be used to launch instances. These templates are referred to as images. Amazon provides these images in the form of AMIs (Amazon Machine Images).

  • Allows you to install custom applications and services.

  • Scaling of infrastructure i.e., up or down is easy based on the demand you face.

  • AWS provides multiple configurations of CPU, memory, storage, etc., through which you can pick the flavor that's required for your environment.

What is Amazon S3?

  • S3 stands for Simple Storage Service.

  • It provides object storage through a web service interface.

  • Each object is stored as a file with its metadata included and is given an ID number.

  • Objects uploaded to S3 are stored in containers called “Buckets”, whose names are globally unique. They organize the Amazon S3 namespace at the highest level.

  • Amazon S3 creates buckets in the region you specify.

  • You can assign permissions to these buckets to provide or restrict data transactions.

What is Terraform?

  • It is an open-source IaaC (Infrastructure as a code) software tool where you define and create resources using providers in the declarative configuration language example JSON.

  • With Terraform, You can package and reuse the code in form of modules.

  • It supports a number of cloud infrastructure providers such as AWS, Azure, GCP, IBM Cloud, OCI, etc. 

  • Terraform has four major commands:

    • terraform init

    • terraform plan

    • terraform apply

    • terraform destroy

Prerequisite

Architecture Diagram

Task Details

  1. Launching Lab Environment

  2. Setup Visual Studio Code

  3. Create a variables file

  4. Create an S3 Bucket and its components in main.tf file

  5. Confirm the installation of Terraform by checking the version

  6. Apply terraform configuration

  7. Check the resources in AWS Console

  8. Validation of the lab

  9. Delete resources