LocalStack: AWS Resource

Mehedee Hassan
2 min readJan 1, 2024

--

Experiment AWS resource creation locally

Introduction

In short, this post will guide us on practicing Terraform and AWS resource creation locally. By the end, we should have a local environment set up for experimenting with Terraform.

After setting up the environment, we will perform two operations:

  1. Create an S3 bucket.
  2. Upload a local file to the S3 bucket.

Pre-requisite

wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
  • Terraform local : download
  • Local AWS CLI:
pip install awscli-local

Fire Up

Let’s start all the components and configure.

  1. Start localstack container
# Pull docker image
docker run --rm -it -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack
localstack start -d

2. To configure AWS, you can use the following configurations:

Note: region should be us-east-1

# mhr@mhr$ aws configure 

AWS Access Key ID []: test
AWS Secret Access Key []: test
Default region name [us-east-1]: us-east-1
Default output format [json]: json

Resource Creation (locally)

Let’s create an S3 bucket and verify its existence in our localstack.

If we currently check with awslocal, we won't find a bucket named my-bucket.

my-bucket

As we can see there are no s3 bucket called my-bucket.

  1. Create a file main.tf
resource "aws_s3_bucket" "test-bucket" {
bucket = "my-bucket"
}

2. Initialize and Apply terraform changes.

tflocal init
Initialize terraform
tflocal apply
Apply changes

Voilà!!!! .. our s3 bucket my-bucket has been created on our local stack docker container.

We can upload and check if it really works.

Uploading A file to our new s3 bucket

Conclusions

I hope this post helps you set up a local environment for practicing basic AWS resource creation. Feel free to experiment with the configurations and create more advanced resources.

Thank you.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Mehedee Hassan
Mehedee Hassan

No responses yet

Write a response