Skip to content

Commit fb27a0b

Browse files
authored
Add GUIDE (#6)
* minor changes on npm script * add DEVGUIDE
1 parent a33ed38 commit fb27a0b

File tree

3 files changed

+110
-73
lines changed

3 files changed

+110
-73
lines changed

DEVGUIDE.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## Developer Guide
2+
3+
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`.
4+
5+
To build and deploy your application for the first time, run the following commands in your shell using `makefile` (only for macOS and Linux):
6+
7+
```bash
8+
make i
9+
make build
10+
make deploy
11+
```
12+
13+
The second command will build the source of your application. The 3rd command will package and deploy your application to AWS, with a series of prompts:
14+
15+
* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name.
16+
* **AWS Region**: The AWS region you want to deploy your app to.
17+
* **Confirm changes before deploy**: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes.
18+
* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modifies IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command.
19+
* **Save arguments to samconfig.toml**: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application.
20+
21+
You can find your API Gateway Endpoint URL in the output values displayed after deployment.
22+
23+
## Use the SAM CLI to build and test locally
24+
25+
Build your application with the `make build` command.
26+
27+
```bash
28+
ts-lambda-kit$ make build
29+
```
30+
31+
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.
32+
33+
Test a single function by invoking it directly with a test event. An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the `events` folder in this project.
34+
35+
Run functions locally and invoke them with the `sam local invoke` command.
36+
37+
```bash
38+
ts-lambda-kit$ sam local invoke {lambda-function-name} --event events/event.json
39+
```
40+
41+
The SAM CLI can also emulate your application's API. Use the `sam local start-api` to run the API locally on port 3000.
42+
43+
```bash
44+
ts-lambda-kit$ sam local start-api
45+
ts-lambda-kit$ curl http://localhost:3000/
46+
```
47+
48+
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.
49+
50+
```yaml
51+
Events:
52+
ApiGatewayRouteGetUsers:
53+
Type: Api
54+
Properties:
55+
Path: /users
56+
Method: GET
57+
RestApiId:
58+
Ref: RestApiGateway
59+
```
60+
61+
## Add a resource to your application
62+
The application template uses AWS Serverless Application Model (AWS SAM) to define application resources. AWS SAM is an extension of AWS CloudFormation with a simpler syntax for configuring common serverless application resources such as functions, triggers, and APIs. For resources not included in [the SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use standard [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html) resource types.
63+
64+
## Fetch, tail, and filter Lambda function logs
65+
66+
To simplify troubleshooting, SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug.
67+
68+
`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM.
69+
70+
```bash
71+
ts-lambda-kit$ sam logs -n {lambda-function-name} --stack-name typescript-aws-lambda-serverless-restapi-kit --tail
72+
```
73+
74+
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).
75+
76+
## Unit tests
77+
78+
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.
79+
80+
```bash
81+
ts-lambda-kit$ npm install
82+
ts-lambda-kit$ npm run test
83+
```
84+
85+
## Cleanup
86+
87+
To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following:
88+
89+
```bash
90+
make destroy
91+
```
92+
93+
## Resources
94+
95+
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.
96+
97+
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/)
98+
99+

README.md

+8-72
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ To build and deploy your application for the first time, run the following comma
5858
make i
5959
make build
6060
make deploy
61+
make destroy
6162
```
6263

63-
The first command will build the source of your application. The second command will package and deploy your application to AWS, with a series of prompts:
64+
The 2nd command will build the source of your application. The 3rd command will package and deploy your application to AWS, with a series of prompts:
6465

6566
* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name.
6667
* **AWS Region**: The AWS region you want to deploy your app to.
@@ -70,81 +71,16 @@ The first command will build the source of your application. The second command
7071

7172
You can find your API Gateway Endpoint URL in the output values displayed after deployment.
7273

73-
## Use the SAM CLI to build and test locally
74-
75-
Build your application with the `make build` command.
76-
77-
```bash
78-
ts-lambda-kit$ make build
79-
```
80-
81-
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.
82-
83-
Test a single function by invoking it directly with a test event. An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the `events` folder in this project.
84-
85-
Run functions locally and invoke them with the `sam local invoke` command.
86-
87-
```bash
88-
ts-lambda-kit$ sam local invoke {lambda-function-name} --event events/event.json
89-
```
90-
91-
The SAM CLI can also emulate your application's API. Use the `sam local start-api` to run the API locally on port 3000.
92-
93-
```bash
94-
ts-lambda-kit$ sam local start-api
95-
ts-lambda-kit$ curl http://localhost:3000/
96-
```
97-
98-
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.
99-
100-
```yaml
101-
Events:
102-
ApiGatewayRouteGetUsers:
103-
Type: Api
104-
Properties:
105-
Path: /users
106-
Method: GET
107-
RestApiId:
108-
Ref: RestApiGateway
109-
```
110-
111-
## Add a resource to your application
112-
The application template uses AWS Serverless Application Model (AWS SAM) to define application resources. AWS SAM is an extension of AWS CloudFormation with a simpler syntax for configuring common serverless application resources such as functions, triggers, and APIs. For resources not included in [the SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use standard [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html) resource types.
113-
114-
## Fetch, tail, and filter Lambda function logs
115-
116-
To simplify troubleshooting, SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug.
117-
118-
`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM.
119-
120-
```bash
121-
ts-lambda-kit$ sam logs -n {lambda-function-name} --stack-name typescript-aws-lambda-serverless-restapi-kit --tail
122-
```
123-
124-
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).
125-
126-
## Unit tests
127-
128-
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.
129-
130-
```bash
131-
ts-lambda-kit$ npm install
132-
ts-lambda-kit$ npm run test
133-
```
134-
135-
## Cleanup
136-
137-
To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following:
138-
139-
```bash
140-
make destroy
141-
```
74+
#### 🎯 For more information, please check out out [details guide](https://github.com/DevSazal/ts-lambda-kit/blob/main/DEVGUIDE.md)
75+
<br />
14276

143-
## Resources
77+
## Key Resources
14478

14579
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.
14680

147-
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/)
81+
## Contributing
82+
83+
Contributions are more than welcome! We are excited to explore how we can create something truly remarkable together!
14884

14985
## License
15086

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
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",
18+
"bin": {
19+
"ts-lambda-kit": "bin/install.js"
20+
},
1921
"scripts": {
2022
"unit": "jest",
2123
"lint": "eslint '*.ts' --quiet --fix",

0 commit comments

Comments
 (0)