This project implements a secure TCP server with TLS encryption and integration with AWS DynamoDB. It allows basic CRUD operations (CREATE, READ, UPDATE, DELETE) on a DynamoDB table and communicates over a TLS-encrypted connection.
- TLS Encryption: Ensures secure communication between the client and server.
- DynamoDB Integration: Performs CRUD operations on a DynamoDB table.
- Dockerized Setup: Easily deployable using Docker.
- Go: Install Go (version 1.23.4 or later).
- Docker: Install Docker.
- DynamoDB Table: Create a DynamoDB table in your AWS account.
git clone https://github.com/Waramoto/tcp-aws-crud.git
cd tcp-aws-crud
Generate a self-signed certificate for TLS communication:
mkdir cert
openssl req -x509 -newkey rsa:2048 -keyout cert/server.key -out cert/server.crt -days 365 -nodes -subj "/CN=localhost"
Copy the .env.example
file into the .env
file and configure it on your own:
cp .env.example .env
Build and run the server locally:
go run -o server ./cmd/server/main.go
Build and run the server using Docker:
docker build -t tcp-aws-crud .
docker run -d -p 8080:8080 \
--name tcp-aws-crud \
--env-file .env \
-v $(pwd)/cert:/app/cert \
tcp-aws-crud
Run the client locally:
go run ./cmd/client/main.go 127.0.0.1:8080 --tls-skip-verify
You can also test the server using netcat:
ncat --ssl 127.0.0.1 8080
-
CREATE: Add an item to the DynamoDB table.
>> CREATE id123 HelloWorld ->: SUCCESS CREATE
-
READ: Retrieve an item from the DynamoDB table.
>> READ id123 ->: SUCCESS READ: HelloWorld
-
UPDATE: Update an existing item.
>> UPDATE id123 NewData ->: SUCCESS UPDATE
-
DELETE: Remove an item from the DynamoDB table.
>> DELETE id123 ->: SUCCESS DELETE
-
Invalid Command:
>> INVALID ->: Failed : unknown command. Use CREATE, READ, UPDATE, DELETE
-
TLS Certificate Verification:
- Use the
--tls-skip-verify
flag for self-signed certificates during testing. - For production, use a valid TLS certificate and omit this flag.
- Use the
-
DynamoDB Permissions:
- Ensure your AWS IAM role or user has the necessary permissions to access the specified DynamoDB table.
-
Error Handling:
- The client and server log errors to the console for debugging.
-
Certificate Not Found:
- Ensure the
cert
directory is correctly mounted in Docker.
- Ensure the
-
Invalid Reference Format in Docker:
- Ensure the
docker run
command uses the correct syntax for environment files and volume mounts.
- Ensure the
-
DynamoDB Access Errors:
- Verify your AWS credentials and permissions.
This project is licensed under the MIT License.