Skip to content

Commit e30a8c4

Browse files
feat: added readme file
Signed-off-by: kapish <upadhyaykapish@gmail.com>
1 parent d950006 commit e30a8c4

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

sqs-samples/README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# SQS LocalStack Setup
2+
3+
This guide will walk you through setting up **LocalStack** with **SQS**, **MongoDB**, and interacting with the services using `awslocal`. We'll also walk through building the repository, sending test messages to SQS, and using Keploy to record and test the application.
4+
5+
## Prerequisites
6+
7+
Before proceeding, ensure you have the following installed:
8+
9+
- **Docker** (for running MongoDB)
10+
- **Python 3** (for installing LocalStack using `pipx`)
11+
- **Go** (for building the Go application)
12+
- **Keploy** (for recording and testing)
13+
14+
---
15+
16+
## Step 1: Set up LocalStack
17+
18+
### 1.1 Install LocalStack via `pipx`
19+
20+
First, install **`pipx`** (if not already installed):
21+
22+
```bash
23+
python3 -m pip install --upgrade pipx
24+
python3 -m pipx ensurepath
25+
```
26+
Now, install LocalStack using pipx:
27+
```
28+
pipx install --include-deps localstack
29+
```
30+
31+
32+
After installing LocalStack, install the AWS CLI Local tool (awslocal):
33+
```
34+
pipx inject localstack awscli-local
35+
pipx ensurepath
36+
```
37+
38+
This will allow you to interact with LocalStack using awslocal.
39+
1.2 **Start LocalStack**
40+
41+
Start LocalStack in the background:
42+
43+
```
44+
localstack start -d
45+
```
46+
Wait for LocalStack to initialize. It may take a few seconds to be fully ready.
47+
48+
## Step 2: **Set up MongoDB with Docker**
49+
50+
51+
### 2.1 Run MongoDB
52+
We will now run MongoDB using Docker. Use the following command to start MongoDB in a Docker container:
53+
```
54+
docker run -p 27017:27017 --rm --network keploy-network --name mongoDb mongo
55+
```
56+
57+
## Step 3: Set up SQS Queue in LocalStack
58+
### 3.1 Create SQS Queue
59+
You can create an SQS queue in LocalStack using awslocal. First, create the SQS queue with the following command:
60+
61+
```
62+
awslocal sqs create-queue --queue-name localstack-queue
63+
```
64+
This will create a queue named localstack-queue.
65+
66+
### 3.2 Populate the SQS Queue
67+
To populate the SQS queue with some test messages, use the following commands:
68+
69+
```
70+
awslocal sqs send-message --queue-url http://localhost:4566/000000000000/localstack-queue --message-body "Test message 1"
71+
72+
awslocal sqs send-message --queue-url http://localhost:4566/000000000000/localstack-queue --message-body "Test message 2"
73+
```
74+
This sends two test messages to the localstack-queue in LocalStack.
75+
76+
## Step 4: Build the Repository
77+
## 4.1 Build the Go Application
78+
After setting up LocalStack and MongoDB, it's time to build your Go application. Navigate to your repository directory and run the following:
79+
80+
```
81+
go mod tidy
82+
go build -o ginApp .
83+
```
84+
This will build the Go application and output the executable ginApp.
85+
86+
## Step 5: Run the Application
87+
Start the application (assuming it's a Gin application) using:
88+
89+
```
90+
./ginApp
91+
```
92+
Ensure the application is running before proceeding with the next steps.
93+
94+
## Step 6: Send Requests Using curl
95+
## 6.1 Send POST Request to Shorten URL
96+
Use curl to send a POST request to your application (adjust the URL accordingly if your app runs on a different port):
97+
98+
```
99+
curl --request POST --url http://localhost:8080/url --header 'Content-Type: application/json' --data '{"url": "https://google.com"}'
100+
```
101+
This will send a URL to your application to be shortened.
102+
103+
## 6.2 Send GET Request to Retrieve the URL
104+
After the URL is shortened, you can use curl to send a GET request to retrieve the shortened URL:
105+
106+
```
107+
curl --request GET http://localhost:8080/Lhr4BWAi
108+
```
109+
Make sure to replace Lhr4BWAi with the actual shortened URL ID returned from the POST request.
110+
111+
## Step 7: Keploy - Record and Test
112+
### 7.1 Run Keploy Record
113+
Start Keploy in record mode to capture the interactions between your application and the services (LocalStack, MongoDB):
114+
115+
```
116+
sudo -E env PATH=$PATH <path to your keploy binary> record -c "./ginApp"
117+
```
118+
Hit the curl commands and populate sqs queue to mimic the working behaiviour
119+
120+
This will run your application in record mode and capture all interactions with LocalStack and MongoDB.
121+
122+
### 7.2 Run Keploy Test
123+
Once the interactions are captured, you can run Keploy in test mode to validate the captured requests:
124+
125+
```
126+
sudo -E env PATH=$PATH <path to your keploy binary> test -c "go run main.go" --delay 30 &> logs.txt
127+
```
128+
This will execute the recorded tests and output the results to test_logs.txt.

0 commit comments

Comments
 (0)