Skip to content
Star
478
Star
478

SQL Writer

This guide shows you how to build a hybrid cloud scenario using LocalStack and an external PostgreSQL instance. This lab demonstrates how an AWS Lambda retrieves secrets from Secrets Manager and interacts with a database outside the AWS environment.

  1. Setup Environment:

    Open VS Code in the project folder and execute this command in the Command Palette:

    Terminal window
    > Dev Containers: Reopen in Container
  2. Then configure the AWS CLI:

    Terminal window
    aws configure set aws_access_key_id test
    aws configure set aws_secret_access_key test
    aws configure set region us-east-1
  3. Deploy Resources:

    Terminal window
    python package_lambda.py
    terraform init && terraform apply -auto-approve
  4. Run the Example:

    Terminal window
    aws --endpoint-url=http://localhost:4566 lambda invoke \
    --function-name AddUserFunction \
    --payload '{}' \
    response.json
  1. Check using DBeaver: Connect to the local PostgreSQL instance and run the following query:

    • Host: localhost.
    • Port: 5432.
    • Database: mydb.
    • User: myuser.
    • Password: mypassword.
    SELECT * FROM users ORDER BY created_at DESC;
  2. Check using AWS CLI:

    • List Lambda Functions:
      Terminal window
      aws --endpoint-url=http://localhost:4566 lambda list-functions
    • Check Secrets:
      Terminal window
      aws --endpoint-url=http://localhost:4566 secretsmanager list-secrets
Terminal window
terraform destroy -auto-approve
docker compose down -v
rm lambda.zip response.json
IssueSolution
Connection RefusedEnsure host.docker.internal is reachable from the LocalStack container. For older Docker on Linux, add it to extra_hosts in docker-compose.yml.
Port Already in UseModify the port mappings for 4566 or 5432 in docker-compose.yml.