Deploying LocalStack ?? using Docker

Deploying LocalStack ?? using Docker

LocalStack is a fully functional local AWS cloud stack that enables you to develop and test your cloud and serverless apps offline. It provides an easy-to-use test/mocking framework for developing cloud applications and supports various AWS services

First of all we are going to pull the localstack image needed and then

This will start the docker container with LocalStack running inside it

# Pull the docker image
docker pull localstack/localstack

# Run the docker container
docker run -d -p 4566:4566 -p 4571:4571 localstack/localstack
        

Creating a Bucket in LocalStack

To interact with LocalStack, we’ll use the AWS CLI.

If you don't have it on your machine and your using Windows , you can install and run it from here: https://awscli.amazonaws.com/AWSCLIV2.msi

or you can access the deployed container and run it from in there by using this command (replace container id with your localstack container id)

docker exec -it <container-id> bash        

However, we need to configure it to interact with LocalStack and not the real AWS services. Here’s how you can do it:

# Configure AWS CLI for LocalStack
aws configure --profile localstack
        

Enter https://localhost:4566 for the endpoint and us-east-1 for the region. You can leave access key, secret key, and session token as none

Now, let’s create a bucket:

# Create a bucket
aws --endpoint-url=https://localhost:4566 --profile localstack s3 mb s3://my-bucket
        

This will create a bucket named my-bucket.

Using Terraform to deploy our mock instances

So we are going to deploy our instances using this tf file so that you can see all your created instances on LocalStack

This will create 10 instances for example:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.27"
    }
  }

  required_version = ">= 0.13.4"
}

provider "aws" {
  access_key                  = "test"
  secret_key                  = "test"
  region                      = "us-east-1"
  s3_force_path_style         = false
  skip_credentials_validation = true
  skip_metadata_api_check     = true
  skip_requesting_account_id  = true

  endpoints {
    apigateway     = "https://localhost:4566"
    apigatewayv2   = "https://localhost:4566"
    cloudformation = "https://localhost:4566"
    cloudwatch     = "https://localhost:4566"
    dynamodb       = "https://localhost:4566"
    ec2            = "https://localhost:4566"
    es             = "https://localhost:4566"
    elasticache    = "https://localhost:4566"
    firehose       = "https://localhost:4566"
    iam            = "https://localhost:4566"
    kinesis        = "https://localhost:4566"
    lambda         = "https://localhost:4566"
    rds            = "https://localhost:4566"
    redshift       = "https://localhost:4566"
    route53        = "https://localhost:4566"
    s3             = "https://s3.localhost.localstack.cloud:4566"
    secretsmanager = "https://localhost:4566"
    ses            = "https://localhost:4566"
    sns            = "https://localhost:4566"
    sqs            = "https://localhost:4566"
    ssm            = "https://localhost:4566"
    stepfunctions  = "https://localhost:4566"
    sts            = "https://localhost:4566"
  }
}

resource "aws_instance" "myserver" {
  ami           = "ami-830c94e3"
  instance_type = "t2.micro"
  count = 10

  tags = {
    Name = "Server${count.index + 1}",
  }
}        

To apply and create the mock instances using terraform

#initializes various local settings and data that will be used by subsequent commands

terraform init

#will show you a plan of what it will do and will prompt you for approval before making any changes

terraform apply        

To check on your instances you can run the below:

aws --endpoint-url=https://localhost:4566 ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,InstanceType,PublicIpAddress,Tags[?Key==`Name`]| [0].Value]' --output table --region us-east-1
        

and your displayed result should look like this:

10 mock instances

LocalStack is a great example to test locally your setups and applications as well as to get familiar with the AWS ecosystem and it can provide the following:

  • No Infrastructure Management Overhead: LocalStack runs on your local machine, eliminating the need for managing cloud infrastructure.
  • Cost-Effective: It helps avoid incurring costs associated with AWS, especially during the early stages of development.
  • Offline Development: LocalStack allows you to develop and test your applications offline.
  • Ease of Use: It provides the same APIs as real AWS services, allowing you to use familiar tools like the official AWS CLI and AWS SDK3.
  • Simplified Configuration: It helps avoid the complexity of AWS configuration, letting you focus more on development.
  • CI/CD Integration: LocalStack can be integrated into your CI/CD pipeline for running tests.
  • Error Scenario Testing: It allows you to configure and test error scenarios, which can be crucial for building robust applications.
  • Support for Multiple AWS Services: LocalStack supports various AWS services, making it a comprehensive tool for practicing AWS.


Remember, while LocalStack is a great tool for local development and testing, it’s not a replacement for testing in a real AWS environment before going live. Always ensure your applications work as expected in the actual AWS environment.


#LocalStack #Docker #AWS #CloudComputing #Serverless #S3Bucket


As always support the projects:

https://github.com/devopsjourney1/localstack-101

and his amazing channel on:

https://www.youtube.com/@DevOpsJourney




要查看或添加评论,请登录

Mohamed Sharfy的更多文章

  • Deploy Portainer?????

    Deploy Portainer?????

    Portainer is a popular graphical user interface (GUI) for managing Docker environments. It provides a simple and…

  • Stirling PDF??

    Stirling PDF??

    Stirling PDF is a powerful, locally hosted web-based PDF manipulation tool that allows you to perform various…

  • Deploy SuperSet??

    Deploy SuperSet??

    Apache Superset is a powerful, open-source data visualization tool. In this article, we’ll walk through the process of…

  • Deploying HEIMDALL ??

    Deploying HEIMDALL ??

    Heimdall Application Dashboard is a powerful tool that allows you to organize your services and applications in a…

  • Deploying Peppermint ??

    Deploying Peppermint ??

    Hello, LinkedIn community! Today, I’m excited to share with you how i deployed Peppermint using Docker. For those who…

  • Deploying Uptime Kuma?? and Notifications with a Telegram Bot

    Deploying Uptime Kuma?? and Notifications with a Telegram Bot

    Hello everyone! Today, I’m going to walk you through the process of deploying Uptime Kuma ??, a self-hosted monitoring…

  • Deploy Ntfy ??

    Deploy Ntfy ??

    In the world of DevOps, Docker has emerged as a revolutionary tool that simplifies the process of building, shipping…

  • Deploying your own PrivateGPT ??

    Deploying your own PrivateGPT ??

    As a systems administrator, I am always looking for ways to improve my skills and learn new technologies. Recently, I…

  • Deploying Wazuh ?? !

    Deploying Wazuh ?? !

    Hi everyone, I hope you are having a great day. I wanted to share with you my personal experience deploying Wazuh SIEM…

    1 条评论

社区洞察

其他会员也浏览了