Skip to content

Commit 9bb052d

Browse files
committed
Readme edits
1 parent 4d9431d commit 9bb052d

6 files changed

+35
-21
lines changed

README.md

+35-21
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Use this method for simple use cases where a single static payload is sufficient
88

99
1. Save your payload into a file, e.g. save `{"command": "echo"}` into `test-payload.json`
1010
2. Start the emulator with the payload file name as its only param, e.g. `runtime-emulator test-payload.json`
11-
3. Run `runtime-emulator/env-emulator.sh` script to create required environmental variables
12-
4. Start your lambda with `cargo run`
11+
3. Start your lambda with `cargo run`
1312

1413
The lambda will connect to the emulator and receive the payload.
1514
You can re-run your lambda with the same payload as many times as needed.
@@ -37,6 +36,8 @@ This Lambda emulator does not provide the full runtime capabilities of AWS:
3736
* panics are not reported back to AWS
3837
* no concurrent request handling
3938
* no support for X-Trace or Extensions APIs
39+
* no stream responses
40+
* smaller maximum payload size
4041

4142
## Getting started with remote debugging
4243

@@ -65,8 +66,6 @@ Recommended queue settings:
6566
This IAM policy grants _proxy-lambda_ access to the queues.
6667
It assumes that you already have sufficient privileges to access Lambda and SQS from your local machine.
6768

68-
Replace _Principal_ and _Resource_ IDs with your values before adding this policy to the queue config.
69-
7069
```json
7170
{
7271
"Version": "2012-10-17",
@@ -87,6 +86,10 @@ Replace _Principal_ and _Resource_ IDs with your values before adding this polic
8786
]
8887
}
8988
```
89+
#### Modifying the policy with your IDs
90+
91+
You need to replace _Principal_ and _Resource_ IDs with your values before adding the above policy to your queues:
92+
9093
- _Principal_ - is the IAM role your lambda assumes (check Lambda's Permissions Config tab in the AWS console to find the value)
9194
- _Resource_ - the ARN of the queue the policy is attached to (see the queue details page in the AWS console to find the value)
9295

@@ -98,9 +101,9 @@ Use different _Resource_ values for _request_ and _response_ queues:
98101

99102
### Building and deploying _proxy-lambda_
100103

101-
The _proxy lambda_ function should be deployed to AWS Lambda in place of the function you want to debug.
104+
The _proxy-lambda_ function should be deployed to AWS in place of the function you want to debug.
102105

103-
Replace the following parts of the snippet with your values before running it from the project root:
106+
Replace the following parts of the bash script below with your values before running it from the project root:
104107
- _target_ - the architecture of the lambda function on AWS, e.g. `x86_64-unknown-linux-gnu`
105108
- _region_ - the region of the lambda function, e.g. `us-east-1`
106109
- _name_ - the name of the lambda function you want to replace with the proxy, e.g. `my-lambda`
@@ -115,7 +118,8 @@ cp ./target/$target/release/proxy-lambda ./bootstrap && zip proxy.zip bootstrap
115118
aws lambda update-function-code --region $region --function-name $name --zip-file fileb://proxy.zip
116119
```
117120

118-
A deployed _proxy-lambda_ should return _OK_ or time out waiting for a response if you run it with a test event from the AWS console. Check CloudWatch logs for a detailed execution report.
121+
A deployed _proxy-lambda_ should return _OK_ or time out waiting for a response if you run it with a test event from the AWS console.
122+
Check CloudWatch logs for a detailed execution report.
119123

120124
### Debugging
121125

@@ -127,8 +131,8 @@ __Pre-requisites:__
127131

128132
__Launching the local lambda:__
129133
- start the _runtime-emulator_ in the terminal as a binary or with `cargo run`
130-
- run [env-lambda.sh](env-lambda.sh) in a terminal window on your local machine
131-
- start your lambda in the same terminal window with `cargo run`
134+
- add environmental variables from the prompt printed by the _runtime-emulator_ to the lambda terminal
135+
- start your lambda with `cargo run`
132136

133137
![launch example](/img/emulator-launch.png)
134138

@@ -139,13 +143,13 @@ __Debugging:__
139143

140144
__Success, failure and replay:__
141145

142-
- successful responses are sent back to the caller if the response queue is configured
146+
- successful responses are sent back to the caller if the response queue is configured (`proxy_lambda_resp`)
143147
- panics or handler errors are not sent back to AWS
144148
- the same incoming SQS message is reused until the lambda completes successfully
145-
- _runtime-emulator_ deletes the incoming message (request) when the local lambda completes successfully
146-
- _proxy-lambda_ deletes the outgoing message (response) after forwarding it to the caller
147-
- _proxy-lambda_ clears the response queue before forwarding a request
148-
- purge the request queue manually to delete stale requests
149+
- _runtime-emulator_ deletes the request message from `proxy_lambda_req` queue when the local lambda completes successfully
150+
- _proxy-lambda_ deletes the response message from `proxy_lambda_resp` queue after forwarding it to the caller, e.g. to API Gateway
151+
- _proxy-lambda_ purges `proxy_lambda_resp` queue before sending a new request to `proxy_lambda_resp`
152+
- you have to purge `proxy_lambda_req` queue manually to delete stale requests
149153

150154
If the local lambda fails, terminates or panics, you can make changes to its code and run it again to reuse the same incoming payload from the request queue.
151155

@@ -162,26 +166,36 @@ Provide these env vars to _proxy-lambda_ and _runtime-emulator_ if your queue na
162166

163167
### Late responses
164168

165-
Debugging the local lambda may take longer than the AWS service is willing to wait. For example, _proxy-lambda_ function can be configured to wait for up to 15 minutes, but the AWS API Gateway wait time is limited to 30 seconds. If a response from the local lambda arrives after 5 minutes, the _proxy-lambda_ can still forward it to the API Gateway, but that service would already time out. You may need to re-run the request for it to complete successfully end-to-end.
169+
Debugging the local lambda may take longer than the AWS service is willing to wait.
170+
For example, _proxy-lambda_ function can be configured to wait for up to 15 minutes, but the AWS API Gateway wait time is limited to 30 seconds.
171+
172+
Assume that it took you 5 minutes to fix the lambda code and return the correct response.
173+
If _proxy-lambda_ was configured to wait for that long it would still forward the response to the API Gateway which timed out 4.5 min earlier.
174+
In that case, you may need to trigger another request for it to complete successfully end-to-end.
166175

167176
### Not waiting for responses from local lambda
168177

169-
It may be inefficient to have _proxy-lambda_ waiting for a response from the local lambda.
178+
It may be inefficient to have _proxy-lambda_ waiting for a response from the local lambda because it takes too long or no response is necessary.
179+
Both _proxy-lambda_ and _runtime-emulator_ would not expect a response if the response queue is inaccessible.
170180

171181
Option 1: delete _proxy_lambda_resp_ queue
172182

173-
Option 2: add `PROXY_LAMBDA_RESP_QUEUE_URL` env var with no value to instruct _proxy-lambda_ and _runtime-emulator_ to not wait for the local lambda response
183+
Option 2: add `PROXY_LAMBDA_RESP_QUEUE_URL` env var with no value to _proxy-lambda_ and _runtime-emulator_
174184

175-
Option 3: make _proxy_lambda_resp_ queue inaccessible by changing its IAM policy. E.g. change the resource name from the correct queue name `"Resource": "arn:aws:sqs:us-east-1:512295225992:proxy_lambda_resp"` to `"Resource": "arn:aws:sqs:us-east-1:512295225992:proxy_lambda_resp_BLOCKED"`.
176-
Both, _proxy-lambda_ and _runtime-emulator_ treat the access error as a hint to not expect a response.
185+
Option 3: make _proxy_lambda_resp_ queue inaccessible by changing its IAM policy.
186+
E.g. change the resource name from the correct queue name `"Resource": "arn:aws:sqs:us-east-1:512295225992:proxy_lambda_resp"` to a non-existent name like this `"Resource": "arn:aws:sqs:us-east-1:512295225992:proxy_lambda_resp_BLOCKED"`.
187+
Both _proxy-lambda_ and _runtime-emulator_ treat the access error as a hint to not expect a response.
177188

178189
### Canceling long _proxy-lambda_ wait
179190

180-
Send a random message to the response queue via the AWS console to make _proxy-lambda_ exit and become available for a new request.
191+
If your _proxy-lambda_ is configured to expect a long debugging time, e.g. 30 minutes, you may want to cancel the wait for a rerun.
192+
Since it is impossible to kill a running lambda instance on AWS, the easiest way to cancel the wait is to send a random message to `proxy_lambda_resp` queue via the AWS console.
193+
The waiting _proxy-lambda_ will forward it to the caller and become available for a new request.
181194

182195
### Large payloads and data compression
183196

184-
The size of the SQS payload is [limited to 262,144 bytes by SQS](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html). To get around this limitation _proxy-lambda_ and _runtime-emulator_ compress oversized payloads using [flate2 crate](https://crates.io/crates/flate2) and send it as an encoded Base58 string. The encoding/decoding happens automatically at both ends.
197+
The size of the SQS payload is [limited to 262,144 bytes by SQS](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html) while [Lambda allows up to 6MB](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html).
198+
_proxy-lambda_ and _runtime-emulator_ compress oversized payloads using [flate2 crate](https://crates.io/crates/flate2) and send them as an encoded Base58 string to get around that limitation.
185199

186200
The data compression can take up to a minute in debug mode. It is significantly faster with release builds.
187201

img/emulator-launch.png

26.7 KB
Loading

img/lambda-debugger-components.png

85.3 KB
Loading

img/lambda-debugger-usecase.png

55.4 KB
Loading

img/schematics.png

-34.2 KB
Binary file not shown.

img/sequence.png

-46.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)