When you add a Lambda Function in AWS Amplify, a template is generated in JavaScript, so this is a memo on how to turn it into TypeScript.
The following document was used as a reference
procedure
When you add a Function, the following folder is generated for you to work in.
amplify/backend/function/[function_name]
TypeScript program
Create a ts folder and place a program written in TypeScript there.
mkdir ts touch ts/index.ts
tsconfig.json
Create tsconfig.json
{ "compilerOptions": { "allowSyntheticDefaultImports": true, "lib": [ "dom", "esnext" ], "module": "commonjs", "moduleResolution": "node", "skipLibCheck": true, "resolveJsonModule": true, "outDir": "./src", "baseUrl": "./", "rootDir": "./ts", "paths": { "src": [ "./ts" ] } } }
package.json
Create package.json (excerpt scripts)
{ "scripts": { "build": "tsc && cp package.json src/ && cd src && rm -f package-lock.json && npm install --production && npm prune --production && rm -f package.json && rm -f package-lock.json" } }
Update Operation
build
Run in function folder
npm run build
test
amplify mock function [function_name]
deploy
amplify push
supplementary explanation
The point is that the files/folders in the src folder will be uploaded to Lambda, so only Dependencies modules should be installed in the src folder.
However, if package.json is in the src folder, the devDependencies module will also be installed when mock or push is performed, so the package.json file should be deleted after the modules are installed.
Impressions, etc.
I have been creating Lambda using the Serverless Framework, but I am struggling to pull it closer to AWS Amplify when using AWS Amplify.