Skip to content

Commit d23c322

Browse files
authored
Merge pull request #467 from awsdocs/AWSRoman/layer-typescript
TypeScript layer example
2 parents 1a2f22b + ad07fed commit d23c322

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Handler } from 'aws-lambda';
2+
import * as _ from 'lodash';
3+
4+
type User = {
5+
user: string;
6+
active: boolean;
7+
}
8+
9+
type UserResult = {
10+
statusCode: number;
11+
body: string;
12+
}
13+
14+
const users: User[] = [
15+
{ 'user': 'Carlos', 'active': true },
16+
{ 'user': 'Gil-dong', 'active': false },
17+
{ 'user': 'Pat', 'active': false }
18+
];
19+
20+
export const handler: Handler<any, UserResult> = async (): Promise<UserResult> => {
21+
22+
let out = _.findLastIndex(users, (user: User) => { return user.user == 'Pat'; });
23+
const response = {
24+
statusCode: 200,
25+
body: JSON.stringify(out + ", " + users[out].user),
26+
};
27+
return response;
28+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "lambda-typescript-layer-example",
3+
"version": "1.0.0",
4+
"main": "dist/index.js",
5+
"scripts": {
6+
"prebuild": "rm -rf dist",
7+
"build": "tsc index.ts --module nodenext --lib es2020 --outDir dist/",
8+
"postbuild": "cd dist && zip -r index.zip index.js",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"author": "",
12+
"license": "MIT-0",
13+
"description": "",
14+
"devDependencies": {
15+
"@types/aws-lambda": "^8.10.145",
16+
"@types/lodash": "^4.17.9",
17+
"lodash": "^4.17.21",
18+
"typescript": "^5.6.2"
19+
}
20+
}

0 commit comments

Comments
 (0)