Skip to content

Commit b15ccbb

Browse files
committed
Create a basic TypeScript example
1 parent 824682e commit b15ccbb

File tree

6 files changed

+116
-0
lines changed

6 files changed

+116
-0
lines changed

aws-node-typescript/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# package directories
2+
node_modules
3+
.esbuild
4+
5+
# Serverless directories
6+
.serverless

aws-node-typescript/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!--
2+
title: 'AWS TypeScript Example'
3+
description: 'This template demonstrates how to deploy a TypeScript function running on AWS Lambda using Serverless Framework.'
4+
layout: Doc
5+
framework: v3
6+
platform: AWS
7+
language: nodeJS
8+
priority: 1
9+
authorLink: 'https://github.com/serverless'
10+
authorName: 'Serverless, inc.'
11+
authorAvatar: 'https://avatars1.githubusercontent.com/u/13742415?s=200&v=4'
12+
-->
13+
14+
15+
# Serverless Framework AWS TypeScript Example
16+
17+
This template demonstrates how to deploy a TypeScript function running on AWS Lambda using Serverless Framework. The deployed function does not include any event definitions as well as any kind of persistence (database). For more advanced configurations check out the [examples repo](https://github.com/serverless/examples/) which includes integrations with SQS, DynamoDB or examples of functions that are triggered in `cron`-like manner. For details about configuration of specific `events`, please refer to our [documentation](https://www.serverless.com/framework/docs/providers/aws/events/).
18+
19+
## Usage
20+
21+
### Deployment
22+
23+
In order to deploy the example, you need to run the following command:
24+
25+
```
26+
$ serverless deploy
27+
```
28+
29+
After running deploy, you should see output similar to:
30+
31+
```bash
32+
Deploying aws-node-typescript to stage dev (us-east-1)
33+
34+
✔ Service deployed to stack aws-node-typescript-dev (112s)
35+
36+
functions:
37+
hello: aws-node-typescript-dev-hello (806 B)
38+
```
39+
40+
### Invocation
41+
42+
After successful deployment, you can invoke the deployed function by using the following command:
43+
44+
```bash
45+
serverless invoke --function hello
46+
```
47+
48+
Which should result in response similar to the following:
49+
50+
```json
51+
{
52+
"message": "Go Serverless v3! Your function executed successfully!",
53+
"input": {}
54+
}
55+
```
56+
57+
### Local development
58+
59+
You can invoke your function locally by using the following command:
60+
61+
```bash
62+
serverless invoke local --function hello
63+
```
64+
65+
Which should result in response similar to the following:
66+
67+
```
68+
{
69+
"message": "Go Serverless v3! Your function executed successfully!",
70+
"input": {}
71+
}
72+
```

aws-node-typescript/handler.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export async function hello(event) {
2+
return {
3+
message: 'Go Serverless v3! Your function executed successfully!',
4+
input: event,
5+
};
6+
}

aws-node-typescript/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"devDependencies": {
3+
"esbuild": "^0.14.25",
4+
"serverless-esbuild": "^1.25.0"
5+
}
6+
}

aws-node-typescript/serverless.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
service: aws-node-typescript # NOTE: update this with your service name
2+
frameworkVersion: '3'
3+
4+
provider:
5+
name: aws
6+
runtime: nodejs14.x
7+
8+
functions:
9+
hello:
10+
handler: handler.hello
11+
12+
plugins:
13+
- serverless-esbuild

examples.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,19 @@
435435
"authorName": "Luciano Pellacani Franca",
436436
"authorAvatar": "https://avatars2.githubusercontent.com/u/8251208?v=4&s=140"
437437
},
438+
{
439+
"title": "AWS TypeScript example",
440+
"name": "aws-node-typescript",
441+
"description": "This template demonstrates how to deploy a TypeScript function running on AWS Lambda using the traditional Serverless Framework.",
442+
"githubUrl": "https://github.com/serverless/examples/tree/master/aws-node-typescript",
443+
"framework": "v2",
444+
"language": "node",
445+
"platform": "aws",
446+
"authorLink": "https://github.com/serverless",
447+
"authorName": "Serverless, inc.",
448+
"authorAvatar": "https://avatars1.githubusercontent.com/u/13742415?s=200&v=4",
449+
"priority": 1
450+
},
438451
{
439452
"title": "AWS Simple HTTP Endpoint example in NodeJS with Typescript",
440453
"name": "aws-node-rest-api-typescript-simple",

0 commit comments

Comments
 (0)