Skip to content

Commit 799e7b4

Browse files
authored
Merge pull request #4 from dev branch
update readme
2 parents f7b0d37 + e2407e7 commit 799e7b4

File tree

4 files changed

+129
-23
lines changed

4 files changed

+129
-23
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
.PHONY: build build_cloudformation build_typescript clean clean_cache clean_dist clean_modules clean_tmp deploy deployci deploy_cloudformation destroy destroy_cloudformation lint lintfix
1+
.PHONY: build build_cloudformation build_typescript clean clean_cache clean_dist clean_modules clean_tmp deploy deployci deploy_cloudformation destroy destroy_cloudformation lint lintfix
22

33
#### input params
44
debug = debug
55
maintenance = false
66
region = eu-central-1
7-
stack = typescript-aws-lambda-serverless-restapi-kit
7+
stack = typescript-aws-lambda-serverless-restapi-kit # decide a stack-name for the app
88
stage = v1
99
substage = sazal # x/developer-name
1010
tests = unit
@@ -57,7 +57,7 @@ build_cloudformation:
5757
@sam build -b .aws-sam/build -t serverless.yml \
5858
--cached \
5959
--cache-dir .cache \
60-
--parallel
60+
--parallel
6161

6262
build_typescript:
6363
@npx --no-install tsc

README.md

+52-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
# `ts-lambda-kit`
2+
3+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
4+
25
#### A quick-start kit to Build REST API's using Typescript, AWS Lambda & SAM CLI.
6+
7+
8+
By running single command, you will get a `production-ready` [TypeScript](https://typescriptlang.org) lambda application and fully configured on your machine. Our goal is to provide you with a very cool, opinionated architecture. It will provide you with things like generic functionalities for the [lambda](https://docs.aws.amazon.com/lambda/) function and cool request handling support with [Amazon API Gateway](https://aws.amazon.com/api-gateway/), [AWS CloudFormation](https://aws.amazon.com/cloudformation/), and [Amazon DynamoDB](https://aws.amazon.com/dynamodb/).
9+
10+
It makes things very easy when the question comes with build, and deploy. It has a strong focus on making sure everything is developer-friendly.
11+
12+
13+
### Requirements:
14+
15+
* Node.js - [Install Node.js 18](https://nodejs.org/en/)
16+
* NPM
17+
* TypeScript
18+
* Git
19+
* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
20+
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) optional.
21+
22+
23+
## Quick Installation
24+
25+
To create a project, simply run:
26+
27+
```bash
28+
npx ts-lambda-kit <project-name>
29+
```
30+
31+
or
32+
33+
```bash
34+
npm init ts-lambda-kit <project-name>
35+
```
36+
37+
#### 🥇 Cool! You are ready to make your amazing product.
38+
#### 🎯 I know you liked it. Please, give a star to the [repository](https://github.com/DevSazal/ts-lambda-kit.git)
339
<br />
40+
41+
## Architecture
442
This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders.
543

644
- `src` - Code for the application's Lambda function written in TypeScript.
@@ -10,21 +48,11 @@ This project contains source code and supporting files for a serverless applicat
1048

1149
The application uses several AWS resources, including Lambda functions and an API Gateway API. These resources are defined in the `serverless.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code.
1250

13-
## Deploy the sample application
51+
## Developer Guide
1452

15-
The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API.
53+
install `awscliv2`, `aws-sam-cli`, `nodejs 18` (and `make` only for macOS and Linux) on your machine and ensure that your aws iam account is configured. the configuration profile should be located at `~/.aws/config`, access credentials should be located at `~/.aws/credentials`.
1654

17-
To use the SAM CLI, you need the following tools.
18-
19-
* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
20-
* Node.js - [Install Node.js 18](https://nodejs.org/en/), including the NPM package management tool.
21-
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) optional.
22-
23-
#### setup note
24-
25-
install `awscliv2`, `aws-sam-cli`, `nodejs 18` (and `make` only for macOS and Linux) on your machine and ensure that your aws iam account configured. the configuration profile should be located at `~/.aws/config`, access credentials should be located at `~/.aws/credentials`.
26-
27-
To build and deploy your application for the first time, run the following in your shell using `makefile`:
55+
To build and deploy your application for the first time, run the following commands in your shell using `makefile` (only for macOS and Linux):
2856

2957
```bash
3058
make i
@@ -47,7 +75,7 @@ You can find your API Gateway Endpoint URL in the output values displayed after
4775
Build your application with the `make build` command.
4876

4977
```bash
50-
typescript-aws-lambda-serverless-restapi-kit$ make build
78+
ts-lambda-kit$ make build
5179
```
5280

5381
The SAM CLI installs dependencies defined in `package.json`, compiles TypeScript with esbuild, creates a deployment package, and saves it in the `.aws-sam/build` folder.
@@ -57,14 +85,14 @@ Test a single function by invoking it directly with a test event. An event is a
5785
Run functions locally and invoke them with the `sam local invoke` command.
5886

5987
```bash
60-
typescript-aws-lambda-serverless-restapi-kit$ sam local invoke {lambda-function-name} --event events/event.json
88+
ts-lambda-kit$ sam local invoke {lambda-function-name} --event events/event.json
6189
```
6290

6391
The SAM CLI can also emulate your application's API. Use the `sam local start-api` to run the API locally on port 3000.
6492

6593
```bash
66-
typescript-aws-lambda-serverless-restapi-kit$ sam local start-api
67-
typescript-aws-lambda-serverless-restapi-kit$ curl http://localhost:3000/
94+
ts-lambda-kit$ sam local start-api
95+
ts-lambda-kit$ curl http://localhost:3000/
6896
```
6997

7098
The SAM CLI reads the application template to determine the API's routes and the functions that they invoke. The `Events` property on each function's definition includes the route and method for each path.
@@ -90,7 +118,7 @@ To simplify troubleshooting, SAM CLI has a command called `sam logs`. `sam logs`
90118
`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM.
91119

92120
```bash
93-
typescript-aws-lambda-serverless-restapi-kit$ sam logs -n {lambda-function-name} --stack-name typescript-aws-lambda-serverless-restapi-kit --tail
121+
ts-lambda-kit$ sam logs -n {lambda-function-name} --stack-name typescript-aws-lambda-serverless-restapi-kit --tail
94122
```
95123

96124
You can find more information and examples about filtering Lambda function logs in the [SAM CLI Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html).
@@ -100,8 +128,8 @@ You can find more information and examples about filtering Lambda function logs
100128
Tests are defined in the `__tests__` folder in this project. Use NPM to install the [Jest test framework](https://jestjs.io/) and run unit tests.
101129

102130
```bash
103-
typescript-aws-lambda-serverless-restapi-kit$ npm install
104-
typescript-aws-lambda-serverless-restapi-kit$ npm run test
131+
ts-lambda-kit$ npm install
132+
ts-lambda-kit$ npm run test
105133
```
106134

107135
## Cleanup
@@ -117,3 +145,7 @@ make destroy
117145
See the [AWS SAM developer guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) for an introduction to SAM specification, the SAM CLI, and serverless application concepts.
118146

119147
Next, you can use AWS Serverless Application Repository to deploy ready to use Apps that go beyond hello world samples and learn how authors developed their applications: [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/)
148+
149+
## License
150+
151+
ISC © 2023

bin/install.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env node
2+
3+
const { execSync } = require('child_process');
4+
const path = require('path');
5+
const fs = require('fs');
6+
7+
// Validate Arguments
8+
if (process.argv.length < 3) {
9+
console.log('You have to provide a name for your lambda backend app.');
10+
console.log('For example :');
11+
console.log(' npx ts-lambda-kit my-app');
12+
console.log(' OR');
13+
console.log(' npm init ts-lambda-kit my-app');
14+
process.exit(1);
15+
}
16+
17+
// define constants
18+
const projectName = process.argv[2];
19+
const currentPath = process.cwd();
20+
const projectPath = path.join(currentPath, projectName);
21+
const git_repo = 'https://github.com/DevSazal/ts-lambda-kit.git';
22+
23+
// check if directory already exists
24+
try {
25+
fs.mkdirSync(projectPath);
26+
} catch (err) {
27+
if (err.code === 'EEXIST') {
28+
console.log(`The folder ${projectName} already exist in the current directory, please give it another name.`);
29+
} else {
30+
console.log(error);
31+
}
32+
process.exit(1);
33+
}
34+
35+
async function main() {
36+
try {
37+
console.log('\n');
38+
console.log(`Downloading files...`);
39+
console.log(`repository: ${git_repo}`);
40+
console.log('\n');
41+
execSync(`git clone --depth 1 ${git_repo} ${projectPath}`);
42+
43+
process.chdir(projectPath);
44+
45+
console.log('\n');
46+
console.log(`Installing dependencies...`);
47+
execSync('npm install');
48+
49+
// remove extra files
50+
console.log('\n');
51+
console.log(`Cleaning the workspace...`);
52+
execSync('npx rimraf ./.git'); // delete .git folder
53+
54+
fs.unlinkSync(path.join(projectPath, 'bin', 'install.js'));
55+
fs.rmdirSync(path.join(projectPath, 'bin'), { recursive: true });
56+
57+
// end notes
58+
console.log('\n');
59+
console.log('Installation is now complete!');
60+
console.log('This is ready to use.');
61+
console.log('\n');
62+
console.log('We suggest that you start by typing:');
63+
console.log(` cd ${projectName}`);
64+
console.log();
65+
console.log('Enjoy your typescript lambda app, which will provide you some ready-made features!');
66+
console.log();
67+
} catch (error) {
68+
console.log(error);
69+
}
70+
}
71+
72+
main();

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"url": "https://github.com/DevSazal/ts-lambda-kit/issues"
1616
},
1717
"homepage": "https://github.com/DevSazal/ts-lambda-kit#readme",
18+
"bin": "bin/install.js",
1819
"scripts": {
1920
"unit": "jest",
2021
"lint": "eslint '*.ts' --quiet --fix",
@@ -31,6 +32,7 @@
3132
"@types/node": "^18.11.9",
3233
"@typescript-eslint/eslint-plugin": "^5.10.2",
3334
"@typescript-eslint/parser": "^5.10.2",
35+
"colors": "^1.4.0",
3436
"esbuild-jest": "^0.5.0",
3537
"eslint": "^8.8.0",
3638
"eslint-config-prettier": "^8.3.0",

0 commit comments

Comments
 (0)