Skip to content

deploy localstack

paul-breen edited this page Feb 25, 2025 · 1 revision

We install the LocalStack software into a Python virtual env and then install the AWS CLI software.

Installing LocalStack

Follow this guide:

Create the virtual env and do some initial setup:

$ python3.11 -m venv ve
$ . ve/bin/activate
$ pip install wheel
$ pip install pip --upgrade

Install the localstack package:

$ pip install localstack

Installing awscli

Follow this guide, linked to from the above LocalStack guide:

The awscli package is in the Ubuntu (22.04) apt package repositories, but it is v1:

$ apt search awscli
Sorting... Done
Full Text Search... Done
awscli/jammy,jammy 1.22.34-1 all
  Universal Command Line Environment for AWS

The guide suggests installing v2. Futhermore, it says that the snap package is the official one, hence we will install the snap version (see the 'Snap package' tab in the above guide). First, search the snap package repositories:

$ snap find awscli
Name     Version  Publisher  Notes    Summary
aws-cli  2.24.7   aws✓       classic  Universal Command Line Interface for Amazon Web Services

Now we can go ahead and install it:

$ sudo snap install aws-cli --classic
aws-cli (v2/stable) 2.24.7 from Amazon Web Services (aws✓) installed

and check that it installed OK:

$ aws --version
aws-cli/2.24.7 Python/3.12.6 Linux/5.15.0-124-generic exe/x86_64.ubuntu.22

Configuring LocalStack and starting the daemon

We configure the localstack instance:

$ aws configure 
AWS Access Key ID:test
AWS Secret Access Key:test
Default region name :us-east-1
Default output format[None]

This creates the directory ~/.aws/ containing config and credentials files.

Now we can start the daemon:

$ localstack start -d

     __                     _______ __             __
    / /   ____  _________ _/ / ___// /_____ ______/ /__
   / /   / __ \/ ___/ __ `/ /\__ \/ __/ __ `/ ___/ //_/
  / /___/ /_/ / /__/ /_/ / /___/ / /_/ /_/ / /__/ ,<
 /_____/\____/\___/\__,_/_//____/\__/\__,_/\___/_/|_|

- LocalStack CLI: 4.1.1
- Profile: default
- App: https://app.localstack.cloud

[16:54:43] starting LocalStack in Docker mode 🐳               localstack.py:512
           preparing environment                               bootstrap.py:1321
           configuring container                               bootstrap.py:1329
           container image not found on host                   bootstrap.py:1310
[16:55:10] download complete                                   bootstrap.py:1314
           starting container                                  bootstrap.py:1339
[16:55:13] detaching                                           bootstrap.py:1343

This will be listening on http://localhost:4566.

Use awscli to interact with LocalStack

We can now go ahead a create a test S3 bucket in LocalStack:

$ aws --endpoint-url=http://localhost:4566 s3api create-bucket --bucket testbucket
{
    "Location": "/testbucket"
}

and list our buckets:

$ aws --endpoint-url=http://localhost:4566 s3api list-buckets
{
    "Buckets": [
        {
            "Name": "testbucket",
            "CreationDate": "2025-02-19T16:59:06+00:00"
        }
    ],
    "Owner": {
        "DisplayName": "webfile",
        "ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
    },
    "Prefix": null
}

Now let's create a test file:

$ echo "This is a test text file." > test.txt

and then copy this file to the bucket:

$ aws --endpoint-url=http://localhost:4566 s3 cp test.txt s3://testbucket
upload: ./test.txt to s3://testbucket/test.txt                  

Create a bucket to hold ApRES data for testing bas-apres

$ aws --endpoint-url=http://localhost:4566 s3api create-bucket --bucket apres-tests
{
    "Location": "/apres-tests"
}
$ aws --endpoint-url=http://localhost:4566 s3 cp bas-apres/tests/short-test-data.dat s3://apres-tests
upload: ../../apres/tests/short-test-data.dat to s3://apres-tests/short-test-data.dat

We can list the files (objects) in the apres-bucket:

$ aws --endpoint-url=http://localhost:4566 s3api list-objects --bucket apres-tests
{
    "Contents": [
        {
            "Key": "short-test-data.dat",
            "LastModified": "2025-02-19T17:14:18+00:00",
            "ETag": "\"31a6562c2df51b538955715fac472c37\"",
            "ChecksumAlgorithm": [
                "CRC64NVME"
            ],
            "ChecksumType": "FULL_OBJECT",
            "Size": 1804,
            "StorageClass": "STANDARD",
            "Owner": {
                "DisplayName": "webfile",
                "ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
            }
        }
    ],
    "RequestCharged": null,
    "Prefix": ""
}

or more succinctly using the ls subcommand of the s3 command (as opposed to s3api). Note that the full URI syntax is optional:

$ aws --endpoint-url=http://localhost:4566 s3 ls s3://apres-tests
2025-02-19 17:14:18       1804 short-test-data.dat
$ aws --endpoint-url=http://localhost:4566 s3 ls apres-tests
2025-02-19 17:14:18       1804 short-test-data.dat

Similarly, we can list all buckets in a more succinct manner than list-buckets by using ls:

$ aws --endpoint-url=http://localhost:4566 s3 ls
2025-02-19 16:59:06 testbucket
2025-02-19 17:13:38 apres-tests
Clone this wiki locally