Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit da84421

Browse files
Add "Local development" to README.md
1 parent 7ed69f1 commit da84421

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

README.md

+85
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,91 @@ make upload_lambda_layer
358358
make update_lambda
359359
```
360360

361+
# Local development
362+
363+
Development and test can be simplified by using a sandboxed local environment replicating of the AWS Lambda by using the [lambci/lambda:provided](https://github.com/lambci/docker-lambda) Docker image.
364+
365+
The local sandboxed Lambda can be launched just to test the Lambda once or more than once.
366+
367+
To run the sandboxed Lambda environment it's required to share the files contained in the layer, the boostrap and the files required by the build with the ```lambci/lambda:provided``` Docker image.
368+
369+
```
370+
docker run --rm \
371+
-v "$(PWD)/$(LOCAL_LAMBDA_PATH)":/var/task:ro,delegated \
372+
-v "$(PWD)/bootstrap":/opt/bootstrap:ro,delegated \
373+
-v "$(PWD)/$(SHARED_LIBS_FOLDER)":/opt/swift-shared-libs:ro,delegated \
374+
lambci/lambda:provided $(LAMBDA_HANDLER) $(LOCAL_LAMBDA_EVENT)
375+
```
376+
377+
- ```$LOCAL_LAMBDA_PATH```: the path containing the build
378+
- ```$SHARED_LIBS_FOLDER```: the path containing the extracted swift runtime libraries
379+
- ```$LAMBDA_HANDLER```: the lambda handler
380+
- ```$LOCAL_LAMBDA_EVENT```: the event json string
381+
382+
383+
To run the Lambda locally follow the [Lambda development workflow](https://github.com/swift-sprinter/aws-lambda-swift-sprinter#lambda-development-workflow) to the step 4:
384+
385+
1) Requirements: Clone the repository and install Docker
386+
2) Prepare a custom docker image: ```make docker_build```
387+
3) Build the lambda layer: ```make package_layer```
388+
4) Write the lambda code
389+
390+
To simplify the local execution swift-sprinter added some useful commands:
391+
392+
## Lambda Local
393+
394+
### Build lambda locally
395+
396+
Build the lambda and copy the artefacts under ```$LOCAL_LAMBDA_PATH```
397+
398+
```make build_lambda_local```
399+
400+
### Invoke lambda local once
401+
402+
Invoke the Lambda locally once with Docker and LambCI on port ```9001```
403+
404+
```make invoke_lambda_local_once```
405+
406+
### Start lamba local environment
407+
408+
Start the local environment with Docker and LambCI on port ```9001```
409+
410+
```make start_lambda_local_env```
411+
412+
Keep it running and open a new terminal window to invoke the lambda.
413+
414+
Use ```ctrl^C``` to stop it.
415+
416+
### Invoke the lambda locally
417+
418+
Invoke the lambda locally using the endpoint ```http://localhost:9001``` with the aws cli.
419+
420+
```make invoke_lambda_local```
421+
422+
## Use of Docker Compose
423+
424+
To test lambda locally with more complex environment it's possible to use Docker Compose.
425+
426+
All the examples in the repository have their own ```docker-compose.yml``` file to run the example locally listening on the port ```9001```.
427+
428+
### Start the Docker Compose
429+
430+
Start the docker-compose test environment
431+
432+
```make start_docker_compose_env```
433+
434+
### Invoke the lambda locally
435+
436+
Invoke the lambda locally using the endpoint ```http://localhost:9001``` with the aws cli.
437+
438+
```make invoke_lambda_local```
439+
440+
### Stop the Docker Compose
441+
442+
Stop the docker-compose test environment
443+
444+
```make stop_docker_compose_env```
445+
361446
# Manual deployment from AWS Console
362447

363448
### Requirements:

0 commit comments

Comments
 (0)