-
Notifications
You must be signed in to change notification settings - Fork 254
Description
Outline 3. Accessing AWS RDS from Locally Running Docker Compose Instances
Accessing AWS RDS from Locally Running Docker Compose Instances
In this chapter, we demonstrate how to access your previously created PostgreSQL RDS service on AWS from your locally running Swift web service using the aws-hummingbird-docker-compose.yaml file. We will configure the Docker Compose file to use the real AWS PostgreSQL endpoint, verify the SSL connection using the eu-central-1-bundle.pem (compiled into the hummingbird-todos image), and test the running service with curl commands similar to those in Chapter 1.
Table of Contents
Overview
- Replace the Placeholder: Update the
<aws_database_endpoint_here>in the Docker Compose file with your AWS PostgreSQL RDS public endpoint. - Region & SSL Verification: We are working in the
eu-central-1(Frankfurt) region. Theeu-central-1-bundle.pemis used to verify the SSL connection to RDS. - Build & Run: Build and run the configuration using a single Docker image (
hummingbird-todos). - Testing: Validate the setup with
curlcommands. - Next Steps: In the upcoming chapter, we will create a VPN connection to the AWS VPC for a more secure access to the RDS instance.
1. Configure the Docker Compose File
Open the aws-hummingbird-docker-compose.yaml file and locate the following environment variable configuration:
services:
hummingbird-todos:
platform: linux/amd64
build:
context: .
dockerfile: hummingbird-docker/Dockerfile
ports:
- "8080:8080"
environment:
DATABASE_HOST: <aws_database_endpoint_here>
DATABASE_PORT: 5432
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_NAME: postgres
ROOT_CERT_PATH: eu-central-1-bundle.pem
command: ["--hostname", "0.0.0.0", "--port", "8080"]Replace <aws_database_endpoint_here> with the actual public endpoint of your AWS PostgreSQL RDS instance. For example, if your endpoint is mydbinstance.abc123def456.eu-central-1.rds.amazonaws.com, update the file accordingly.
2. Build and Run the Docker Compose Setup
Since this setup uses a single Docker image (hummingbird-todos), build the image with:
docker compose -f aws-hummingbird-docker-compose.yaml buildThen, start the container using:
docker compose -f aws-hummingbird-docker-compose.yaml upThis will launch the web service on port 8080 with the proper configuration for connecting to the AWS-hosted PostgreSQL RDS.
3. Test the Web Service
After starting the container, verify that the service is running correctly by using the following curl commands:
Create a Todo
curl -X POST http://localhost:8080/todos \
-H "Content-Type: application/json" \
-d '{"title": "Complete AWS integration", "order": 1}'List All Todos
curl -X GET http://localhost:8080/todosThese tests confirm that the web service is operational and correctly interacting with your AWS RDS instance over a secure SSL connection.
Next Chapter Preview
In the next chapter, we will create a VPN connection to your AWS VPC. This will allow you to access the RDS instance in a more secure way by restricting access to authorized networks only, thereby enhancing the overall security of your application.
Enjoy accessing your AWS RDS service from your locally running Docker Compose instances, and get ready for even more secure connectivity in the upcoming chapter!