diff --git a/sample-apps/layer-typescript/function/index.ts b/sample-apps/layer-typescript/function/index.ts new file mode 100644 index 00000000..83ecea6e --- /dev/null +++ b/sample-apps/layer-typescript/function/index.ts @@ -0,0 +1,28 @@ +import { Handler } from 'aws-lambda'; +import * as _ from 'lodash'; + +type User = { + user: string; + active: boolean; +} + +type UserResult = { + statusCode: number; + body: string; +} + +const users: User[] = [ + { 'user': 'Carlos', 'active': true }, + { 'user': 'Gil-dong', 'active': false }, + { 'user': 'Pat', 'active': false } +]; + +export const handler: Handler = async (): Promise => { + + let out = _.findLastIndex(users, (user: User) => { return user.user == 'Pat'; }); + const response = { + statusCode: 200, + body: JSON.stringify(out + ", " + users[out].user), + }; + return response; +}; diff --git a/sample-apps/layer-typescript/function/package.json b/sample-apps/layer-typescript/function/package.json new file mode 100644 index 00000000..1857273d --- /dev/null +++ b/sample-apps/layer-typescript/function/package.json @@ -0,0 +1,20 @@ +{ + "name": "lambda-typescript-layer-example", + "version": "1.0.0", + "main": "dist/index.js", + "scripts": { + "prebuild": "rm -rf dist", + "build": "tsc index.ts --module nodenext --lib es2020 --outDir dist/", + "postbuild": "cd dist && zip -r index.zip index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "MIT-0", + "description": "", + "devDependencies": { + "@types/aws-lambda": "^8.10.145", + "@types/lodash": "^4.17.9", + "lodash": "^4.17.21", + "typescript": "^5.6.2" + } +}