Skip to content

Commit d9afd6d

Browse files
committed
2 parents dea0c84 + 0ae2ea5 commit d9afd6d

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,62 @@
11
# rust-lambda-starter
2+
3+
[![CI](https://github.com/soupdevsolutions/rust-lambda-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/soupdevsolutions/rust-lambda-starter/actions/workflows/ci.yml)
4+
5+
This is a template for starting serverless projects with AWS Lambda, Rust, and OpenTofu.
6+
7+
## Components
8+
9+
The project contains:
10+
- a Cargo project with an empty library and a **hello_world** binary representing an example Lambda function;
11+
- a Python script for building all the Lambda funtions present in the `./src/bins` directory;
12+
- a base infrastructure written in OpenTofu with IAM, Lambda, and API Gateway resources;
13+
- a CI pipeline that triggers on any PR against the `main` branch or any commit to the `main` branch;
14+
- a CD pipeline that triggers on any push to the `main` branch.
15+
16+
## Usage
17+
18+
### Getting the project
19+
20+
To get a local copy of the template, either use [pont](https://github.com/soupdevsolutions/pont):
21+
22+
```bash
23+
pont build --name <your-project-name> --from https://github.com/soupdevsolutions/rust-lambda-starter
24+
```
25+
26+
or clone the repository and change the occurences of the template name:
27+
28+
```bash
29+
git clone https://github.com/soupdevsolutions/rust-lambda-starter ./<your-project-name>
30+
cd <your-project-name>
31+
32+
# rename the occurences using bash or your IDE tooling
33+
TEMPLATE_NAME_KEBAB_CASE=rust-lambda-starter
34+
TEMPLATE_NAME_SNAKE_CASE=rust_lambda_starter
35+
PROJECT_NAME=<your-project-name>
36+
37+
find . \( -name \*.rs -o -name \*.tf -o -name \*.toml -o -name \*.md -o -name \*.lock \) -exec sed -i '' "s#$TEMPLATE_NAME_KEBAB_CASE#$PROJECT_NAME#g" {} \;
38+
find . \( -name \*.rs -o -name \*.tf -o -name \*.toml -o -name \*.md -o -name \*.lock \) -exec sed -i '' "s#$TEMPLATE_NAME_SNAKE_CASE#$PROJECT_NAME#g" {} \;
39+
```
40+
41+
### Deployment
42+
43+
The recommended way for deploying the project is to use GitHub Actions; however, you can also do it from your local machine.
44+
45+
For deploying with GitHub Actions, push your project to a new repository, go to the repository's **Settings** -> **Secrets and variables** -> **Actions**, and add secrets for your IAM user credentials:
46+
- AWS_ACCESS_KEY_ID -> the access key id
47+
- AWS_SECRET_ACCESS_KEY -> the secret access key
48+
Any push to the `main` branch will trigger both the CI and CD pipelines.
49+
50+
If you choose to deploy from your local machine, make sure to follow the guide for [configuring the AWS CLI](https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-configure.html), so OpenTofu can deploy to your AWS account. Then, you can run all the steps from the CD pipeline locally:
51+
52+
```bash
53+
# init OpenTofu (only needs to be done once locally)
54+
tofu -chdir=infrastructure init
55+
56+
# build the Lambda functions
57+
python3 ./scripts/build.py
58+
59+
# plan and apply the changes
60+
tofu -chdir=infrastructure plan
61+
tofu -chdir=infrastructure apply
62+
```

0 commit comments

Comments
 (0)