From 11c8a730c7d8f391ffbed39898c1d92c1f634620 Mon Sep 17 00:00:00 2001 From: lvthillo Date: Sun, 10 Nov 2024 19:50:30 +0100 Subject: [PATCH 1/2] feat: remove deprecated node16 --- .github/workflows/build_test_invoke.yml | 6 - manifest-v2.json | 116 --------- nodejs16.x/cw-event/.gitignore | 229 ------------------ nodejs16.x/cw-event/README.md | 20 -- nodejs16.x/cw-event/cookiecutter.json | 12 - nodejs16.x/cw-event/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 1 - .../{{cookiecutter.project_name}}/README.md | 140 ----------- .../handlers/scheduled-event-logger.test.js | 30 --- .../buildspec.yml | 23 -- .../events/event-cloudwatch-event.json | 12 - .../package.json | 13 - .../src/handlers/scheduled-event-logger.js | 8 - .../template.yaml | 41 ---- nodejs16.x/hello-img/.gitignore | 229 ------------------ nodejs16.x/hello-img/README.md | 20 -- nodejs16.x/hello-img/cookiecutter.json | 12 - nodejs16.x/hello-img/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 207 ---------------- .../{{cookiecutter.project_name}}/README.md | 116 --------- .../events/event.json | 62 ----- .../hello-world/.npmignore | 1 - .../hello-world/Dockerfile | 10 - .../hello-world/app.js | 33 --- .../hello-world/package.json | 19 -- .../hello-world/tests/unit/test-handler.js | 22 -- .../template.yaml | 48 ---- nodejs16.x/hello-ts-pt/.gitignore | 229 ------------------ nodejs16.x/hello-ts-pt/README.md | 37 --- nodejs16.x/hello-ts-pt/cookiecutter.json | 16 -- nodejs16.x/hello-ts-pt/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 207 ---------------- .../{{cookiecutter.project_name}}/README.md | 182 -------------- .../events/event.json | 62 ----- .../hello-world/.eslintignore | 2 - .../hello-world/.eslintrc.js | 15 -- .../hello-world/.npmignore | 1 - .../hello-world/.prettierrc.js | 7 - .../hello-world/app.ts | 135 ----------- .../hello-world/jest.config.ts | 15 -- .../hello-world/package.json | 37 --- .../tests/unit/test-handler.test.ts | 87 ------- .../hello-world/tsconfig.json | 15 -- .../template.yaml | 70 ------ nodejs16.x/hello-ts/.gitignore | 229 ------------------ nodejs16.x/hello-ts/README.md | 20 -- nodejs16.x/hello-ts/cookiecutter.json | 12 - nodejs16.x/hello-ts/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 207 ---------------- .../{{cookiecutter.project_name}}/README.md | 127 ---------- .../events/event.json | 62 ----- .../hello-world/.eslintignore | 2 - .../hello-world/.eslintrc.js | 15 -- .../hello-world/.npmignore | 1 - .../hello-world/.prettierrc.js | 7 - .../hello-world/app.ts | 33 --- .../hello-world/jest.config.ts | 15 -- .../hello-world/package.json | 34 --- .../tests/unit/test-handler.test.ts | 65 ----- .../hello-world/tsconfig.json | 15 -- .../template.yaml | 54 ----- nodejs16.x/hello/.gitignore | 229 ------------------ nodejs16.x/hello/README.md | 20 -- nodejs16.x/hello/cookiecutter.json | 12 - nodejs16.x/hello/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 207 ---------------- .../{{cookiecutter.project_name}}/README.md | 127 ---------- .../events/event.json | 62 ----- .../hello-world/.npmignore | 1 - .../hello-world/app.js | 33 --- .../hello-world/package.json | 19 -- .../hello-world/tests/unit/test-handler.js | 22 -- .../template.yaml | 46 ---- nodejs16.x/response-streaming/.gitignore | 208 ---------------- nodejs16.x/response-streaming/README.md | 20 -- .../response-streaming/cookiecutter.json | 12 - nodejs16.x/response-streaming/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 208 ---------------- .../{{cookiecutter.project_name}}/README.md | 102 -------- .../__tests__/unit/index.test.js | 41 ---- .../package.json | 24 -- .../src/index.js | 33 --- .../template.yaml | 33 --- nodejs16.x/s3/.gitignore | 229 ------------------ nodejs16.x/s3/README.md | 20 -- nodejs16.x/s3/cookiecutter.json | 12 - nodejs16.x/s3/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 2 - .../{{cookiecutter.project_name}}/README.md | 151 ------------ .../handlers/s3-json-logger-handler.test.js | 37 --- .../buildspec.yml | 22 -- .../events/event-s3.json | 38 --- .../package.json | 16 -- .../src/handlers/s3-json-logger.js | 26 -- .../template.yaml | 47 ---- nodejs16.x/scratch/.gitignore | 229 ------------------ nodejs16.x/scratch/README.md | 20 -- nodejs16.x/scratch/cookiecutter.json | 12 - nodejs16.x/scratch/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 1 - .../{{cookiecutter.project_name}}/README.md | 140 ----------- .../unit/handlers/hello-from-lambda.test.js | 20 -- .../buildspec.yml | 25 -- .../package.json | 13 - .../src/handlers/hello-from-lambda.js | 12 - .../template.yaml | 38 --- nodejs16.x/sns/.gitignore | 229 ------------------ nodejs16.x/sns/README.md | 20 -- nodejs16.x/sns/cookiecutter.json | 12 - nodejs16.x/sns/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 1 - .../{{cookiecutter.project_name}}/README.md | 146 ----------- .../unit/handlers/sns-payload-logger.test.js | 23 -- .../buildspec.yml | 25 -- .../events/event-sns.json | 5 - .../package.json | 13 - .../src/handlers/sns-payload-logger.js | 8 - .../template.yaml | 48 ---- nodejs16.x/sqs/.gitignore | 229 ------------------ nodejs16.x/sqs/README.md | 20 -- nodejs16.x/sqs/cookiecutter.json | 12 - nodejs16.x/sqs/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 1 - .../{{cookiecutter.project_name}}/README.md | 141 ----------- .../unit/handlers/sqs-payload-logger.test.js | 29 --- .../buildspec.yml | 23 -- .../events/event-sqs.json | 11 - .../package.json | 13 - .../src/handlers/sqs-payload-logger.js | 8 - .../template.yaml | 48 ---- nodejs16.x/step-func-conn/.gitignore | 229 ------------------ nodejs16.x/step-func-conn/README.md | 23 -- nodejs16.x/step-func-conn/cookiecutter.json | 12 - nodejs16.x/step-func-conn/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 207 ---------------- .../{{cookiecutter.project_name}}/README.md | 137 ----------- .../functions/stock-buyer/.npmignore | 1 - .../functions/stock-buyer/app.js | 30 --- .../functions/stock-buyer/package.json | 17 -- .../stock-buyer/tests/unit/test-handler.js | 22 -- .../functions/stock-checker/.npmignore | 1 - .../functions/stock-checker/app.js | 19 -- .../functions/stock-checker/package.json | 17 -- .../stock-checker/tests/unit/test-handler.js | 17 -- .../functions/stock-seller/.npmignore | 1 - .../functions/stock-seller/app.js | 30 --- .../functions/stock-seller/package.json | 17 -- .../stock-seller/tests/unit/test-handler.js | 22 -- .../{{cookiecutter.project_name}}/makefile | 71 ------ .../statemachine/stock_trader.asl.json | 97 -------- .../statemachine/test/MockConfigFile.json | 142 ----------- .../template.yaml | 109 --------- nodejs16.x/step-func/.gitignore | 229 ------------------ nodejs16.x/step-func/README.md | 23 -- nodejs16.x/step-func/cookiecutter.json | 12 - nodejs16.x/step-func/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 207 ---------------- .../{{cookiecutter.project_name}}/README.md | 137 ----------- .../functions/stock-buyer/.npmignore | 1 - .../functions/stock-buyer/app.js | 30 --- .../functions/stock-buyer/package.json | 17 -- .../stock-buyer/tests/unit/test-handler.js | 22 -- .../functions/stock-checker/.npmignore | 1 - .../functions/stock-checker/app.js | 19 -- .../functions/stock-checker/package.json | 17 -- .../stock-checker/tests/unit/test-handler.js | 17 -- .../functions/stock-seller/.npmignore | 1 - .../functions/stock-seller/app.js | 30 --- .../functions/stock-seller/package.json | 17 -- .../stock-seller/tests/unit/test-handler.js | 22 -- .../{{cookiecutter.project_name}}/makefile | 71 ------ .../statemachine/stock_trader.asl.json | 97 -------- .../statemachine/test/MockConfigFile.json | 142 ----------- .../template.yaml | 94 ------- nodejs16.x/web-conn/.gitignore | 229 ------------------ nodejs16.x/web-conn/README.md | 20 -- nodejs16.x/web-conn/cookiecutter.json | 12 - nodejs16.x/web-conn/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 1 - .../{{cookiecutter.project_name}}/README.md | 160 ------------ .../unit/handlers/get-all-items.test.js | 45 ---- .../__tests__/unit/handlers/get-by-id.test.js | 50 ---- .../__tests__/unit/handlers/put-item.test.js | 47 ---- .../buildspec.yml | 22 -- .../{{cookiecutter.project_name}}/env.json | 11 - .../events/event-get-all-items.json | 3 - .../events/event-get-by-id.json | 6 - .../events/event-post-item.json | 4 - .../package.json | 16 -- .../src/handlers/get-all-items.js | 37 --- .../src/handlers/get-by-id.js | 40 --- .../src/handlers/put-item.js | 42 ---- .../template.yaml | 131 ---------- nodejs16.x/web/.gitignore | 229 ------------------ nodejs16.x/web/README.md | 20 -- nodejs16.x/web/cookiecutter.json | 12 - nodejs16.x/web/setup.cfg | 2 - .../{{cookiecutter.project_name}}/.gitignore | 1 - .../{{cookiecutter.project_name}}/README.md | 160 ------------ .../unit/handlers/get-all-items.test.js | 45 ---- .../__tests__/unit/handlers/get-by-id.test.js | 50 ---- .../__tests__/unit/handlers/put-item.test.js | 47 ---- .../buildspec.yml | 22 -- .../{{cookiecutter.project_name}}/env.json | 11 - .../events/event-get-all-items.json | 3 - .../events/event-get-by-id.json | 6 - .../events/event-post-item.json | 4 - .../package.json | 16 -- .../src/handlers/get-all-items.js | 47 ---- .../src/handlers/get-by-id.js | 49 ---- .../src/handlers/put-item.js | 51 ---- .../template.yaml | 131 ---------- .../{{cookiecutter.project_name}}/README.md | 2 +- .../{{cookiecutter.project_name}}/README.md | 2 +- .../{{cookiecutter.project_name}}/README.md | 2 +- .../{{cookiecutter.project_name}}/README.md | 2 +- .../{{cookiecutter.project_name}}/README.md | 2 +- .../{{cookiecutter.project_name}}/README.md | 2 +- .../build_invoke/node/test_node_16.py | 62 ----- .../unit_test/test_unit_test_nodejs16_x.py | 71 ------ 220 files changed, 6 insertions(+), 11453 deletions(-) delete mode 100644 nodejs16.x/cw-event/.gitignore delete mode 100644 nodejs16.x/cw-event/README.md delete mode 100644 nodejs16.x/cw-event/cookiecutter.json delete mode 100644 nodejs16.x/cw-event/setup.cfg delete mode 100755 nodejs16.x/cw-event/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/cw-event/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/cw-event/{{cookiecutter.project_name}}/__tests__/unit/handlers/scheduled-event-logger.test.js delete mode 100755 nodejs16.x/cw-event/{{cookiecutter.project_name}}/buildspec.yml delete mode 100644 nodejs16.x/cw-event/{{cookiecutter.project_name}}/events/event-cloudwatch-event.json delete mode 100755 nodejs16.x/cw-event/{{cookiecutter.project_name}}/package.json delete mode 100755 nodejs16.x/cw-event/{{cookiecutter.project_name}}/src/handlers/scheduled-event-logger.js delete mode 100755 nodejs16.x/cw-event/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/hello-img/.gitignore delete mode 100644 nodejs16.x/hello-img/README.md delete mode 100644 nodejs16.x/hello-img/cookiecutter.json delete mode 100644 nodejs16.x/hello-img/setup.cfg delete mode 100644 nodejs16.x/hello-img/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/hello-img/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/hello-img/{{cookiecutter.project_name}}/events/event.json delete mode 100644 nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/.npmignore delete mode 100644 nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/Dockerfile delete mode 100644 nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/app.js delete mode 100644 nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/package.json delete mode 100644 nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.js delete mode 100644 nodejs16.x/hello-img/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/hello-ts-pt/.gitignore delete mode 100644 nodejs16.x/hello-ts-pt/README.md delete mode 100644 nodejs16.x/hello-ts-pt/cookiecutter.json delete mode 100644 nodejs16.x/hello-ts-pt/setup.cfg delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/events/event.json delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.eslintignore delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.eslintrc.js delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.npmignore delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.prettierrc.js delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/app.ts delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/jest.config.ts delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/package.json delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.test.ts delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/tsconfig.json delete mode 100644 nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/hello-ts/.gitignore delete mode 100644 nodejs16.x/hello-ts/README.md delete mode 100644 nodejs16.x/hello-ts/cookiecutter.json delete mode 100644 nodejs16.x/hello-ts/setup.cfg delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/events/event.json delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.eslintignore delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.eslintrc.js delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.npmignore delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.prettierrc.js delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/app.ts delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/jest.config.ts delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/package.json delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.test.ts delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/tsconfig.json delete mode 100644 nodejs16.x/hello-ts/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/hello/.gitignore delete mode 100644 nodejs16.x/hello/README.md delete mode 100644 nodejs16.x/hello/cookiecutter.json delete mode 100644 nodejs16.x/hello/setup.cfg delete mode 100644 nodejs16.x/hello/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/hello/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/hello/{{cookiecutter.project_name}}/events/event.json delete mode 100644 nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/.npmignore delete mode 100644 nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/app.js delete mode 100644 nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/package.json delete mode 100644 nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.js delete mode 100644 nodejs16.x/hello/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/response-streaming/.gitignore delete mode 100644 nodejs16.x/response-streaming/README.md delete mode 100644 nodejs16.x/response-streaming/cookiecutter.json delete mode 100644 nodejs16.x/response-streaming/setup.cfg delete mode 100644 nodejs16.x/response-streaming/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/response-streaming/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/response-streaming/{{cookiecutter.project_name}}/__tests__/unit/index.test.js delete mode 100644 nodejs16.x/response-streaming/{{cookiecutter.project_name}}/package.json delete mode 100644 nodejs16.x/response-streaming/{{cookiecutter.project_name}}/src/index.js delete mode 100644 nodejs16.x/response-streaming/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/s3/.gitignore delete mode 100644 nodejs16.x/s3/README.md delete mode 100644 nodejs16.x/s3/cookiecutter.json delete mode 100644 nodejs16.x/s3/setup.cfg delete mode 100644 nodejs16.x/s3/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/s3/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/s3/{{cookiecutter.project_name}}/__tests__/unit/handlers/s3-json-logger-handler.test.js delete mode 100644 nodejs16.x/s3/{{cookiecutter.project_name}}/buildspec.yml delete mode 100644 nodejs16.x/s3/{{cookiecutter.project_name}}/events/event-s3.json delete mode 100644 nodejs16.x/s3/{{cookiecutter.project_name}}/package.json delete mode 100644 nodejs16.x/s3/{{cookiecutter.project_name}}/src/handlers/s3-json-logger.js delete mode 100644 nodejs16.x/s3/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/scratch/.gitignore delete mode 100644 nodejs16.x/scratch/README.md delete mode 100644 nodejs16.x/scratch/cookiecutter.json delete mode 100644 nodejs16.x/scratch/setup.cfg delete mode 100755 nodejs16.x/scratch/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/scratch/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/scratch/{{cookiecutter.project_name}}/__tests__/unit/handlers/hello-from-lambda.test.js delete mode 100755 nodejs16.x/scratch/{{cookiecutter.project_name}}/buildspec.yml delete mode 100755 nodejs16.x/scratch/{{cookiecutter.project_name}}/package.json delete mode 100755 nodejs16.x/scratch/{{cookiecutter.project_name}}/src/handlers/hello-from-lambda.js delete mode 100755 nodejs16.x/scratch/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/sns/.gitignore delete mode 100644 nodejs16.x/sns/README.md delete mode 100644 nodejs16.x/sns/cookiecutter.json delete mode 100644 nodejs16.x/sns/setup.cfg delete mode 100755 nodejs16.x/sns/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/sns/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/sns/{{cookiecutter.project_name}}/__tests__/unit/handlers/sns-payload-logger.test.js delete mode 100755 nodejs16.x/sns/{{cookiecutter.project_name}}/buildspec.yml delete mode 100644 nodejs16.x/sns/{{cookiecutter.project_name}}/events/event-sns.json delete mode 100755 nodejs16.x/sns/{{cookiecutter.project_name}}/package.json delete mode 100755 nodejs16.x/sns/{{cookiecutter.project_name}}/src/handlers/sns-payload-logger.js delete mode 100755 nodejs16.x/sns/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/sqs/.gitignore delete mode 100644 nodejs16.x/sqs/README.md delete mode 100644 nodejs16.x/sqs/cookiecutter.json delete mode 100644 nodejs16.x/sqs/setup.cfg delete mode 100755 nodejs16.x/sqs/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/sqs/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/sqs/{{cookiecutter.project_name}}/__tests__/unit/handlers/sqs-payload-logger.test.js delete mode 100755 nodejs16.x/sqs/{{cookiecutter.project_name}}/buildspec.yml delete mode 100644 nodejs16.x/sqs/{{cookiecutter.project_name}}/events/event-sqs.json delete mode 100755 nodejs16.x/sqs/{{cookiecutter.project_name}}/package.json delete mode 100755 nodejs16.x/sqs/{{cookiecutter.project_name}}/src/handlers/sqs-payload-logger.js delete mode 100755 nodejs16.x/sqs/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/step-func-conn/.gitignore delete mode 100644 nodejs16.x/step-func-conn/README.md delete mode 100644 nodejs16.x/step-func-conn/cookiecutter.json delete mode 100644 nodejs16.x/step-func-conn/setup.cfg delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/.npmignore delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/app.js delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/package.json delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/tests/unit/test-handler.js delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/.npmignore delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/app.js delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/package.json delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/tests/unit/test-handler.js delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/.npmignore delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/app.js delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/package.json delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/tests/unit/test-handler.js delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/makefile delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/statemachine/stock_trader.asl.json delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/statemachine/test/MockConfigFile.json delete mode 100644 nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/step-func/.gitignore delete mode 100644 nodejs16.x/step-func/README.md delete mode 100644 nodejs16.x/step-func/cookiecutter.json delete mode 100644 nodejs16.x/step-func/setup.cfg delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/.npmignore delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/app.js delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/package.json delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/tests/unit/test-handler.js delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/.npmignore delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/app.js delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/package.json delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/tests/unit/test-handler.js delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/.npmignore delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/app.js delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/package.json delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/tests/unit/test-handler.js delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/makefile delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/statemachine/stock_trader.asl.json delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/statemachine/test/MockConfigFile.json delete mode 100644 nodejs16.x/step-func/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/web-conn/.gitignore delete mode 100644 nodejs16.x/web-conn/README.md delete mode 100644 nodejs16.x/web-conn/cookiecutter.json delete mode 100644 nodejs16.x/web-conn/setup.cfg delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-all-items.test.js delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-by-id.test.js delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/put-item.test.js delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/buildspec.yml delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/env.json delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-get-all-items.json delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-get-by-id.json delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-post-item.json delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/package.json delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/get-all-items.js delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/get-by-id.js delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/put-item.js delete mode 100644 nodejs16.x/web-conn/{{cookiecutter.project_name}}/template.yaml delete mode 100644 nodejs16.x/web/.gitignore delete mode 100644 nodejs16.x/web/README.md delete mode 100644 nodejs16.x/web/cookiecutter.json delete mode 100644 nodejs16.x/web/setup.cfg delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/.gitignore delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/README.md delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-all-items.test.js delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-by-id.test.js delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/put-item.test.js delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/buildspec.yml delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/env.json delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/events/event-get-all-items.json delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/events/event-get-by-id.json delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/events/event-post-item.json delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/package.json delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/get-all-items.js delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/get-by-id.js delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/put-item.js delete mode 100644 nodejs16.x/web/{{cookiecutter.project_name}}/template.yaml delete mode 100644 tests/integration/build_invoke/node/test_node_16.py delete mode 100644 tests/integration/unit_test/test_unit_test_nodejs16_x.py diff --git a/.github/workflows/build_test_invoke.yml b/.github/workflows/build_test_invoke.yml index 594557cc9..c0396cf0a 100644 --- a/.github/workflows/build_test_invoke.yml +++ b/.github/workflows/build_test_invoke.yml @@ -190,12 +190,6 @@ jobs: fail-fast: false matrix: include: - - version: '16' - type: 'Test' - file: 'tests/integration/unit_test/test_unit_test_nodejs16_x.py' - - version: '16' - type: 'Invoke' - file: 'tests/integration/build_invoke/node/test_node_16.py' - version: '18' type: 'Test' file: 'tests/integration/unit_test/test_unit_test_nodejs18_x.py' diff --git a/manifest-v2.json b/manifest-v2.json index 5e5f1100f..eb2abb7ac 100644 --- a/manifest-v2.json +++ b/manifest-v2.json @@ -556,122 +556,6 @@ "useCaseName": "Multi-step workflow" } ], - "nodejs16.x": [ - { - "directory": "nodejs16.x/hello", - "displayName": "Hello World Example", - "dependencyManager": "npm", - "appTemplate": "hello-world", - "packageType": "Zip", - "useCaseName": "Hello World Example" - }, - { - "directory": "nodejs16.x/hello-ts", - "displayName": "Hello World Example TypeScript", - "dependencyManager": "npm", - "appTemplate": "hello-world-typescript", - "packageType": "Zip", - "useCaseName": "Hello World Example" - }, - { - "directory": "nodejs16.x/hello-ts-pt", - "displayName": "Hello World Example TypeScript With Powertools for AWS Lambda", - "dependencyManager": "npm", - "appTemplate": "hello-world-powertools-typescript", - "packageType": "Zip", - "useCaseName": "Hello World Example with Powertools for AWS Lambda" - }, - { - "directory": "nodejs16.x/step-func", - "displayName": "Step Functions Sample App (Stock Trader)", - "dependencyManager": "npm", - "appTemplate": "step-functions-sample-app", - "packageType": "Zip", - "useCaseName": "Multi-step workflow" - }, - { - "directory": "nodejs16.x/scratch", - "displayName": "Quick Start: From Scratch", - "dependencyManager": "npm", - "appTemplate": "quick-start-from-scratch", - "packageType": "Zip", - "useCaseName": "Standalone function" - }, - { - "directory": "nodejs16.x/cw-event", - "displayName": "Quick Start: Scheduled Events", - "dependencyManager": "npm", - "appTemplate": "quick-start-cloudwatch-events", - "packageType": "Zip", - "useCaseName": "Scheduled task" - }, - { - "directory": "nodejs16.x/s3", - "displayName": "Quick Start: S3", - "dependencyManager": "npm", - "appTemplate": "quick-start-s3", - "packageType": "Zip", - "useCaseName": "Data processing" - }, - { - "directory": "nodejs16.x/sns", - "displayName": "Quick Start: SNS", - "dependencyManager": "npm", - "appTemplate": "quick-start-sns", - "packageType": "Zip", - "useCaseName": "Data processing" - }, - { - "directory": "nodejs16.x/sqs", - "displayName": "Quick Start: SQS", - "dependencyManager": "npm", - "appTemplate": "quick-start-sqs", - "packageType": "Zip", - "useCaseName": "Data processing" - }, - { - "directory": "nodejs16.x/web", - "displayName": "Quick Start: Web Backend", - "dependencyManager": "npm", - "appTemplate": "quick-start-web", - "packageType": "Zip", - "useCaseName": "Serverless API" - }, - { - "directory": "nodejs16.x/web-conn", - "displayName": "Quick Start: Web Backend With Connectors", - "dependencyManager": "npm", - "appTemplate": "hello-world-connector", - "packageType": "Zip", - "useCaseName": "Serverless Connector Hello World Example" - }, - { - "directory": "nodejs16.x/step-func-conn", - "displayName": "Step Functions Sample App (Stock Trader) With Connectors", - "dependencyManager": "npm", - "appTemplate": "step-functions-with-connectors", - "packageType": "Zip", - "useCaseName": "Multi-step workflow with Connectors" - }, - { - "directory": "nodejs16.x/response-streaming", - "displayName": "Lambda function using Response Streaming", - "dependencyManager": "npm", - "appTemplate": "response-streaming", - "packageType": "Zip", - "useCaseName": "Lambda Response Streaming" - } - ], - "amazon/nodejs16.x-base": [ - { - "directory": "nodejs16.x/hello-img", - "displayName": "Hello World Image Example", - "dependencyManager": "npm", - "appTemplate": "hello-world-lambda-image", - "packageType": "Image", - "useCaseName": "Hello World Example" - } - ], "nodejs18.x": [ { "directory": "nodejs18.x/hello", diff --git a/nodejs16.x/cw-event/.gitignore b/nodejs16.x/cw-event/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/cw-event/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/cw-event/README.md b/nodejs16.x/cw-event/README.md deleted file mode 100644 index d088b9f58..000000000 --- a/nodejs16.x/cw-event/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS CloudWatch Events Quick Start Application - -A cookiecutter template to create a NodeJS CloudWatch Events Quick Start Application using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x --app-template quick-start-cloudwatch-events --name cwe-app` - -> **NOTE**: ``--name`` allows you to specify a different project folder name - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/cw-event/cookiecutter.json b/nodejs16.x/cw-event/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/cw-event/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/cw-event/setup.cfg b/nodejs16.x/cw-event/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/cw-event/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/cw-event/{{cookiecutter.project_name}}/.gitignore deleted file mode 100755 index b512c09d4..000000000 --- a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff --git a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/README.md b/nodejs16.x/cw-event/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 4af2c7492..000000000 --- a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,140 +0,0 @@ -# {{cookiecutter.project_name}} - -This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) command line interface (CLI). It includes the following files and folders: - -- `src` - Code for the application's Lambda function. -- `events` - Invocation events that you can use to invoke the function. -- `__tests__` - Unit tests for the application code. -- `template.yaml` - A template that defines the application's AWS resources. - -Resources for this project are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open-source plugin for popular IDEs that uses the AWS SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds step-through debugging for Lambda function code. - -To get started, see the following: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The AWS SAM CLI is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the AWS SAM CLI, you need the following tools: - -* AWS SAM CLI - [Install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html). -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the npm package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community). - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -## Use the AWS SAM CLI to build and test locally - -Build your application by using the `sam build` command. - -```bash -my-application$ sam build -``` - -The AWS SAM CLI installs dependencies that are defined in `package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -my-application$ sam local invoke ScheduledEventLogger --event events/event-cloudwatch-event.json -``` - -## Add a resource to your application - -The application template uses 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 that aren't included in the [AWS SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use the standard [AWS CloudFormation resource types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html). - -Update `template.yaml` to add a dead-letter queue to your application. In the **Resources** section, add a resource named **MyQueue** with the type **AWS::SQS::Queue**. Then add a property to the **AWS::Serverless::Function** resource named **DeadLetterQueue** that targets the queue's Amazon Resource Name (ARN), and a policy that grants the function permission to access the queue. - -``` -Resources: - MyQueue: - Type: AWS::SQS::Queue - ScheduledEventLogger: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/scheduled-event-logger.scheduledEventLogger - Runtime: nodejs16.x - DeadLetterQueue: - Type: SQS - TargetArn: !GetAtt MyQueue.Arn - Policies: - - SQSSendMessagePolicy: - QueueName: !GetAtt MyQueue.QueueName -``` - -The dead-letter queue is a location for Lambda to send events that could not be processed. It's only used if you invoke your function asynchronously, but it's useful here to show how you can modify your application's resources and function configuration. - -Deploy the updated application. - -```bash -my-application$ sam deploy -``` - -Open the [**Applications**](https://console.aws.amazon.com/lambda/home#/applications) page of the Lambda console, and choose your application. When the deployment completes, view the application resources on the **Overview** tab to see the new resource. Then, choose the function to see the updated configuration that specifies the dead-letter queue. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, the AWS SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs that are generated by your 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. - -**NOTE:** This command works for all Lambda functions, not just the ones you deploy using AWS SAM. - -```bash -my-application$ sam logs -n ScheduledEventLogger --stack-name sam-app --tail -``` - -**NOTE:** This uses the logical name of the function within the stack. This is the correct name to use when searching logs inside an AWS Lambda function within a CloudFormation stack, even if the deployed function name varies due to CloudFormation's unique resource name generation. - -You can find more information and examples about filtering Lambda function logs in the [AWS SAM CLI documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -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. - -```bash -my-application$ npm install -my-application$ npm run test -``` - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the [AWS SAM Developer Guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html). - -Next, you can use the AWS Serverless Application Repository to deploy ready-to-use apps that go beyond Hello World samples and learn how authors developed their applications. For more information, see the [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) and the [AWS Serverless Application Repository Developer Guide](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html). diff --git a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/__tests__/unit/handlers/scheduled-event-logger.test.js b/nodejs16.x/cw-event/{{cookiecutter.project_name}}/__tests__/unit/handlers/scheduled-event-logger.test.js deleted file mode 100644 index 64c7420e4..000000000 --- a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/__tests__/unit/handlers/scheduled-event-logger.test.js +++ /dev/null @@ -1,30 +0,0 @@ -// Import all functions from scheduled-event-logger.js -const scheduledEventLogger = require('../../../src/handlers/scheduled-event-logger.js'); - -describe('Test for sqs-payload-logger', function () { - // This test invokes the scheduled-event-logger Lambda function and verifies that the received payload is logged - it('Verifies the payload is logged', async () => { - // Mock console.log statements so we can verify them. For more information, see - // https://jestjs.io/docs/en/mock-functions.html - console.info = jest.fn() - - // Create a sample payload with CloudWatch scheduled event message format - var payload = { - "id": "cdc73f9d-aea9-11e3-9d5a-835b769c0d9c", - "detail-type": "Scheduled Event", - "source": "aws.events", - "account": "", - "time": "1970-01-01T00:00:00Z", - "region": "us-west-2", - "resources": [ - "arn:aws:events:us-west-2:123456789012:rule/ExampleRule" - ], - "detail": {} - } - - await scheduledEventLogger.scheduledEventLoggerHandler(payload, null) - - // Verify that console.info has been called with the expected payload - expect(console.info).toHaveBeenCalledWith(JSON.stringify(payload)) - }); -}); diff --git a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/buildspec.yml b/nodejs16.x/cw-event/{{cookiecutter.project_name}}/buildspec.yml deleted file mode 100755 index adb0a1019..000000000 --- a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/buildspec.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 0.2 - -phases: - install: - commands: - # Install all dependencies (including dependencies for running tests) - - npm install - pre_build: - commands: - # Discover and run unit tests in the '__tests__' directory - - npm run test - # Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda - - rm -rf ./__tests__ - # Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json) - - npm prune --production - build: - commands: - # Use AWS SAM to package the application by using AWS CloudFormation - - aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --output-template template-export.yml -artifacts: - type: zip - files: - - template-export.yml diff --git a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/events/event-cloudwatch-event.json b/nodejs16.x/cw-event/{{cookiecutter.project_name}}/events/event-cloudwatch-event.json deleted file mode 100644 index 6c3cb7e3c..000000000 --- a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/events/event-cloudwatch-event.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "id": "cdc73f9d-aea9-11e3-9d5a-835b769c0d9c", - "detail-type": "Scheduled Event", - "source": "aws.events", - "account": "", - "time": "1970-01-01T00:00:00Z", - "region": "us-west-2", - "resources": [ - "arn:aws:events:us-west-2:123456789012:rule/ExampleRule" - ], - "detail": {} -} diff --git a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/package.json b/nodejs16.x/cw-event/{{cookiecutter.project_name}}/package.json deleted file mode 100755 index 57ccc5af5..000000000 --- a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "replaced-by-user-input", - "description": "replaced-by-user-input", - "version": "0.0.1", - "private": true, - "dependencies": {}, - "devDependencies": { - "jest": "^26.6.3" - }, - "scripts": { - "test": "jest" - } -} diff --git a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/src/handlers/scheduled-event-logger.js b/nodejs16.x/cw-event/{{cookiecutter.project_name}}/src/handlers/scheduled-event-logger.js deleted file mode 100755 index cf3750603..000000000 --- a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/src/handlers/scheduled-event-logger.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * A Lambda function that logs the payload received from a CloudWatch scheduled event. - */ -exports.scheduledEventLoggerHandler = async (event, context) => { - // All log statements are written to CloudWatch by default. For more information, see - // https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-logging.html - console.info(JSON.stringify(event)); -} diff --git a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/cw-event/{{cookiecutter.project_name}}/template.yaml deleted file mode 100755 index d2ea1f648..000000000 --- a/nodejs16.x/cw-event/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,41 +0,0 @@ -# This is the SAM template that represents the architecture of your serverless application -# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html - -# The AWSTemplateFormatVersion identifies the capabilities of the template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html -AWSTemplateFormatVersion: 2010-09-09 -Description: >- - {{cookiecutter.project_name}} - -# Transform section specifies one or more macros that AWS CloudFormation uses to process your template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html -Transform: -- AWS::Serverless-2016-10-31 - -# Resources declares the AWS resources that you want to include in the stack -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html -Resources: - # This is the Lambda function definition associated with the source code: sqs-payload-logger.js. For all available properties, see - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - ScheduledEventLogger: - Type: AWS::Serverless::Function - Properties: - Description: A Lambda function that logs the payload of messages sent to an associated SQS queue. - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Handler: src/handlers/scheduled-event-logger.scheduledEventLoggerHandler - # This property associates this Lambda function with a scheduled CloudWatch Event. For all available properties, see - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#schedule - # This example runs every hour. - Events: - CloudWatchEvent: - Type: Schedule - Properties: - Schedule: cron(0 * * * ? *) - MemorySize: 128 - Timeout: 100 diff --git a/nodejs16.x/hello-img/.gitignore b/nodejs16.x/hello-img/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/hello-img/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/hello-img/README.md b/nodejs16.x/hello-img/README.md deleted file mode 100644 index 58d30fe93..000000000 --- a/nodejs16.x/hello-img/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS Hello-world for SAM based Serverless App - -A cookiecutter template to create a NodeJS Hello world boilerplate using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x` - -> **NOTE**: ``--name`` allows you to specify a different project folder name (`sam-app` is the default) - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/hello-img/cookiecutter.json b/nodejs16.x/hello-img/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/hello-img/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/hello-img/setup.cfg b/nodejs16.x/hello-img/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/hello-img/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/hello-img/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 5854f05ec..000000000 --- a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1,207 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test -.env*.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Storybook build outputs -.out -.storybook-out -storybook-static - -# rollup.js default build output -dist/ - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# Temporary folders -tmp/ -temp/ - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam diff --git a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/README.md b/nodejs16.x/hello-img/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index d7f51f9a0..000000000 --- a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,116 +0,0 @@ -# {{ cookiecutter.project_name }} - -This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders. - -- hello-world - Code for the application's Lambda function and Project Dockerfile. -- events - Invocation events that you can use to invoke the function. -- hello-world/tests - Unit tests for the application code. -- template.yaml - A template that defines the application's AWS resources. - -The application uses several AWS resources, including Lambda functions and an API Gateway API. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -## Deploy the sample application - -The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the SAM CLI, you need the following tools. - -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) - -You may need the following for local testing. - -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the NPM package management tool. - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -The first command will build a docker image from a Dockerfile and then the source of your application inside the Docker image. The second command will package and deploy your application to AWS, with a series of prompts: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -You can find your API Gateway Endpoint URL in the output values displayed after deployment. - -## Use the SAM CLI to build and test locally - -Build your application with the `sam build` command. - -```bash -{{ cookiecutter.project_name }}$ sam build -``` - -The SAM CLI builds a docker image from a Dockerfile and then installs dependencies defined in `hello-world/package.json` inside the docker image. The processed template file is saved in the `.aws-sam/build` folder. -* **Note**: The Dockerfile included in this sample application uses `npm install` by default. If you are building your code for production, you can modify it to use `npm ci` instead. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -{{ cookiecutter.project_name }}$ sam local invoke HelloWorldFunction --event events/event.json -``` - -The SAM CLI can also emulate your application's API. Use the `sam local start-api` to run the API locally on port 3000. - -```bash -{{ cookiecutter.project_name }}$ sam local start-api -{{ cookiecutter.project_name }}$ curl http://localhost:3000/ -``` - -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. - -```yaml - Events: - HelloWorld: - Type: Api - Properties: - Path: /hello - Method: get -``` - -## Add a resource to your application -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. - -## Fetch, tail, and filter Lambda function logs - -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. - -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. - -```bash -{{ cookiecutter.project_name }}$ sam logs -n HelloWorldFunction --stack-name {{ cookiecutter.project_name }} --tail -``` - -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). - -## Unit tests - -Tests are defined in the `hello-world/tests` folder in this project. Use NPM to install the [Mocha test framework](https://mochajs.org/) and run unit tests from your local machine. - -```bash -{{ cookiecutter.project_name }}$ cd hello-world -hello-world$ npm install -hello-world$ npm run test -``` - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -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. - -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/) diff --git a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/events/event.json b/nodejs16.x/hello-img/{{cookiecutter.project_name}}/events/event.json deleted file mode 100644 index 070ad8e01..000000000 --- a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/events/event.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "body": "{\"message\": \"hello world\"}", - "resource": "/{proxy+}", - "path": "/path/to/resource", - "httpMethod": "POST", - "isBase64Encoded": false, - "queryStringParameters": { - "foo": "bar" - }, - "pathParameters": { - "proxy": "/path/to/resource" - }, - "stageVariables": { - "baz": "qux" - }, - "headers": { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", - "Accept-Encoding": "gzip, deflate, sdch", - "Accept-Language": "en-US,en;q=0.8", - "Cache-Control": "max-age=0", - "CloudFront-Forwarded-Proto": "https", - "CloudFront-Is-Desktop-Viewer": "true", - "CloudFront-Is-Mobile-Viewer": "false", - "CloudFront-Is-SmartTV-Viewer": "false", - "CloudFront-Is-Tablet-Viewer": "false", - "CloudFront-Viewer-Country": "US", - "Host": "1234567890.execute-api.us-east-1.amazonaws.com", - "Upgrade-Insecure-Requests": "1", - "User-Agent": "Custom User Agent String", - "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", - "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", - "X-Forwarded-For": "127.0.0.1, 127.0.0.2", - "X-Forwarded-Port": "443", - "X-Forwarded-Proto": "https" - }, - "requestContext": { - "accountId": "123456789012", - "resourceId": "123456", - "stage": "prod", - "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", - "requestTime": "09/Apr/2015:12:34:56 +0000", - "requestTimeEpoch": 1428582896000, - "identity": { - "cognitoIdentityPoolId": null, - "accountId": null, - "cognitoIdentityId": null, - "caller": null, - "accessKey": null, - "sourceIp": "127.0.0.1", - "cognitoAuthenticationType": null, - "cognitoAuthenticationProvider": null, - "userArn": null, - "userAgent": "Custom User Agent String", - "user": null - }, - "path": "/prod/path/to/resource", - "resourcePath": "/{proxy+}", - "httpMethod": "POST", - "apiId": "1234567890", - "protocol": "HTTP/1.1" - } -} diff --git a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/.npmignore b/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/Dockerfile b/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/Dockerfile deleted file mode 100644 index 7137aae08..000000000 --- a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM public.ecr.aws/lambda/nodejs:16 - -COPY app.js package*.json ./ - -RUN npm install -# If you are building your code for production, instead include a package-lock.json file on this directory and use: -# RUN npm ci --production - -# Command can be overwritten by providing a different command in the template directly. -CMD ["app.lambdaHandler"] diff --git a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/app.js b/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/app.js deleted file mode 100644 index 695d1b567..000000000 --- a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/app.js +++ /dev/null @@ -1,33 +0,0 @@ -// const axios = require('axios') -// const url = 'http://checkip.amazonaws.com/'; -let response; - -/** - * - * Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format - * @param {Object} event - API Gateway Lambda Proxy Input Format - * - * Context doc: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html - * @param {Object} context - * - * Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html - * @returns {Object} object - API Gateway Lambda Proxy Output Format - * - */ -exports.lambdaHandler = async (event, context) => { - try { - // const ret = await axios(url); - response = { - 'statusCode': 200, - 'body': JSON.stringify({ - message: 'hello world', - // location: ret.data.trim() - }) - } - } catch (err) { - console.log(err); - return err; - } - - return response -}; diff --git a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/package.json b/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/package.json deleted file mode 100644 index 2605186e0..000000000 --- a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "hello_world", - "version": "1.0.0", - "description": "hello world sample for NodeJS", - "main": "app.js", - "repository": "https://github.com/awslabs/aws-sam-cli/tree/develop/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs", - "author": "SAM CLI", - "license": "MIT", - "dependencies": { - "axios": ">=1.6.0" - }, - "scripts": { - "test": "mocha tests/unit/" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^9.1.4" - } -} diff --git a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.js b/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.js deleted file mode 100644 index ae94b9f2f..000000000 --- a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -const app = require('../../app.js'); -const chai = require('chai'); -const expect = chai.expect; -var event, context; - -describe('Tests index', function () { - it('verifies successful response', async () => { - const result = await app.lambdaHandler(event, context) - - expect(result).to.be.an('object'); - expect(result.statusCode).to.equal(200); - expect(result.body).to.be.an('string'); - - let response = JSON.parse(result.body); - - expect(response).to.be.an('object'); - expect(response.message).to.be.equal("hello world"); - // expect(response.location).to.be.an("string"); - }); -}); diff --git a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/hello-img/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index 2f3ef0993..000000000 --- a/nodejs16.x/hello-img/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,48 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - - Sample SAM Template for {{ cookiecutter.project_name }} - -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 3 - MemorySize: 128 - -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function - Properties: - PackageType: Image - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Events: - HelloWorld: - Type: Api - Properties: - Path: /hello - Method: get - Metadata: - DockerTag: {{cookiecutter.runtime}}-v1 - DockerContext: ./hello-world - Dockerfile: Dockerfile - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldApi: - Description: "API Gateway endpoint URL for Prod stage for Hello World function" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" - HelloWorldFunction: - Description: "Hello World Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn diff --git a/nodejs16.x/hello-ts-pt/.gitignore b/nodejs16.x/hello-ts-pt/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/hello-ts-pt/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/hello-ts-pt/README.md b/nodejs16.x/hello-ts-pt/README.md deleted file mode 100644 index 6228f9bc5..000000000 --- a/nodejs16.x/hello-ts-pt/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# AWS SAM cookiecutter for NodeJS TypeScript Lambda functions with Powertools for AWS Lambda (TypeScript) - -**Please note, you should not try to `git clone` this project.** Instead, use `cookiecutter` CLI instead as ``{{cookiecutter.project_name}}`` will be rendered based on your input and therefore all variables and files will be rendered properly. - -## Cookiecutter requirements - -Install `cookiecutter` command line: - -**Pip users**: - -* `pip install cookiecutter` - -**Homebrew users**: - -* `brew install cookiecutter` - -**Windows or Pipenv users**: - -* `pipenv install cookiecutter` - -**NOTE**: [`Pipenv`](https://github.com/pypa/pipenv) is the new and recommended Python packaging tool that works across multiple platforms and makes Windows a first-class citizen. - -### Usage - -Generate a new SAM based Serverless App: `sam init --runtime nodejs16.x`. - -You'll be prompted a few questions to help this cookiecutter template to scaffold this project and after its completed you should see a new folder at your current path with the name of the project you gave as input. - -**NOTE**: After you understand how cookiecutter works (cookiecutter.json, mainly), you can fork this repo and apply your own mechanisms to accelerate your development process and this can be followed for any programming language and OS. - -### Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - -### License - -This project is licensed under the terms of the [MIT License with no attribution](/LICENSE) diff --git a/nodejs16.x/hello-ts-pt/cookiecutter.json b/nodejs16.x/hello-ts-pt/cookiecutter.json deleted file mode 100644 index a367176c2..000000000 --- a/nodejs16.x/hello-ts-pt/cookiecutter.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "Powertools for AWS Lambda (TypeScript) Tracing": ["enabled","disabled"], - "Powertools for AWS Lambda (TypeScript) Metrics": ["enabled","disabled"], - "Powertools for AWS Lambda (TypeScript) Logging": ["enabled","disabled"], - "_copy_without_render": [ - ".gitignore" - ] - -} \ No newline at end of file diff --git a/nodejs16.x/hello-ts-pt/setup.cfg b/nodejs16.x/hello-ts-pt/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/hello-ts-pt/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 5854f05ec..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1,207 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test -.env*.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Storybook build outputs -.out -.storybook-out -storybook-static - -# rollup.js default build output -dist/ - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# Temporary folders -tmp/ -temp/ - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/README.md b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 2bd4d1ac8..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,182 +0,0 @@ -# {{ cookiecutter.project_name }} - -Congratulations, you have just created a Serverless "Hello World" application using the AWS Serverless Application Model (AWS SAM) for the `nodejs16.x` runtime, and options to bootstrap it with [**Powertools for AWS Lambda (TypeScript)**](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/) (Powertools for AWS Lambda (TypeScript)) utilities for Logging, Tracing and Metrics. - -Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serverless best practices and increase developer velocity. - -## Powertools for AWS Lambda (TypeScript) features - -Powertools for AWS Lambda (TypeScript) provides three core utilities: - -* **[Tracer](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/)** - Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions -* **[Logger](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/)** - Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context -* **[Metrics](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) - -Find the complete project's [documentation here](https://awslabs.github.io/aws-lambda-powertools-typescript). - -### Installing Powertools for AWS Lambda (TypeScript) - -You have 2 ways of consuming those utilities: - -* NPM modules -* Lambda Layer - -#### Lambda layers - -The Powertools for AWS Lambda (TypeScript) utilities is packaged as a single [AWS Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-concepts.html#gettingstarted-concepts-layer) - -👉 [Installation guide for the **Powertools for AWS Lambda (TypeScript)** layer](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/#lambda-layer) - -#### NPM modules - -The Powertools for AWS Lambda (TypeScript) utilities follow a modular approach, similar to the official [AWS SDK v3 for JavaScript](https://github.com/aws/aws-sdk-js-v3). - -Each TypeScript utility is installed as standalone NPM package. - -Install all three core utilities at once with this single command: - -```shell -npm install @aws-lambda-powertools/logger @aws-lambda-powertools/tracer @aws-lambda-powertools/metrics -``` - -Or refer to the installation guide of each utility: - -👉 [Installation guide for the **Tracer** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer#getting-started) - -👉 [Installation guide for the **Logger** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger#getting-started) - -👉 [Installation guide for the **Metrics** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics#getting-started) - -### Powertools for AWS Lambda (TypeScript) Examples - -* [CDK](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/cdk) -* [SAM](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/sam) - -## Working with this project - -This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders. - -* hello-world - Code for the application's Lambda function written in TypeScript. -* events - Invocation events that you can use to invoke the function. -* hello-world/tests - Unit tests for the application code. -* template.yaml - A template that defines the application's AWS resources. - -The application uses several AWS resources, including Lambda functions and an API Gateway API. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started. - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -### Deploy the sample application - -The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the SAM CLI, you need the following tools. - -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the NPM package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -You can find your API Gateway Endpoint URL in the output values displayed after deployment. - -### Use the SAM CLI to build and test locally - -Build your application with the `sam build` command. - -```bash -{{ cookiecutter.project_name }}$ sam build -``` - -The SAM CLI installs dependencies defined in `hello-world/package.json`, compiles TypeScript with esbuild, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -{{ cookiecutter.project_name }}$ sam local invoke HelloWorldFunction --event events/event.json -``` - -The SAM CLI can also emulate your application's API. Use the `sam local start-api` to run the API locally on port 3000. - -```bash -{{ cookiecutter.project_name }}$ sam local start-api -{{ cookiecutter.project_name }}$ curl http://localhost:3000/ -``` - -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. - -```yaml - Events: - HelloWorld: - Type: Api - Properties: - Path: /hello - Method: get -``` - -### Add a resource to your application - -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. - -### Fetch, tail, and filter Lambda function logs - -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. - -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. - -```bash -{{ cookiecutter.project_name }}$ sam logs -n HelloWorldFunction --stack-name {{ cookiecutter.project_name }} --tail -``` - -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). - -### Unit tests - -Tests are defined in the `test` folder in this project. - -```bash -{{ cookiecutter.project_name }}$ cd hello-world -hello-world$ npm install -hello-world$ npm run test -``` - -### Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -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. - -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/) diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/events/event.json b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/events/event.json deleted file mode 100644 index 070ad8e01..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/events/event.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "body": "{\"message\": \"hello world\"}", - "resource": "/{proxy+}", - "path": "/path/to/resource", - "httpMethod": "POST", - "isBase64Encoded": false, - "queryStringParameters": { - "foo": "bar" - }, - "pathParameters": { - "proxy": "/path/to/resource" - }, - "stageVariables": { - "baz": "qux" - }, - "headers": { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", - "Accept-Encoding": "gzip, deflate, sdch", - "Accept-Language": "en-US,en;q=0.8", - "Cache-Control": "max-age=0", - "CloudFront-Forwarded-Proto": "https", - "CloudFront-Is-Desktop-Viewer": "true", - "CloudFront-Is-Mobile-Viewer": "false", - "CloudFront-Is-SmartTV-Viewer": "false", - "CloudFront-Is-Tablet-Viewer": "false", - "CloudFront-Viewer-Country": "US", - "Host": "1234567890.execute-api.us-east-1.amazonaws.com", - "Upgrade-Insecure-Requests": "1", - "User-Agent": "Custom User Agent String", - "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", - "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", - "X-Forwarded-For": "127.0.0.1, 127.0.0.2", - "X-Forwarded-Port": "443", - "X-Forwarded-Proto": "https" - }, - "requestContext": { - "accountId": "123456789012", - "resourceId": "123456", - "stage": "prod", - "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", - "requestTime": "09/Apr/2015:12:34:56 +0000", - "requestTimeEpoch": 1428582896000, - "identity": { - "cognitoIdentityPoolId": null, - "accountId": null, - "cognitoIdentityId": null, - "caller": null, - "accessKey": null, - "sourceIp": "127.0.0.1", - "cognitoAuthenticationType": null, - "cognitoAuthenticationProvider": null, - "userArn": null, - "userAgent": "Custom User Agent String", - "user": null - }, - "path": "/prod/path/to/resource", - "resourcePath": "/{proxy+}", - "httpMethod": "POST", - "apiId": "1234567890", - "protocol": "HTTP/1.1" - } -} diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.eslintignore b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.eslintignore deleted file mode 100644 index 512d4cb8b..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -.aws-sam \ No newline at end of file diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.eslintrc.js b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.eslintrc.js deleted file mode 100644 index 5da871fc4..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.eslintrc.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - parser: "@typescript-eslint/parser", - parserOptions: { - ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features - sourceType: "module" - }, - extends: [ - "plugin:@typescript-eslint/recommended", // recommended rules from the @typescript-eslint/eslint-plugin - "plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. - ], - rules: { - // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs - // e.g. "@typescript-eslint/explicit-function-return-type": "off", - } - }; \ No newline at end of file diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.npmignore b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.prettierrc.js b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.prettierrc.js deleted file mode 100644 index 4c2c6c78b..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/.prettierrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - semi: true, - trailingComma: "all", - singleQuote: true, - printWidth: 120, - tabWidth: 4 - }; \ No newline at end of file diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/app.ts b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/app.ts deleted file mode 100644 index b6976fecc..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/app.ts +++ /dev/null @@ -1,135 +0,0 @@ -import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; -{%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Metrics"] == "enabled"%} -import { Metrics } from '@aws-lambda-powertools/metrics'; -{%- endif %} -{%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Logging"] == "enabled"%} -import { Logger } from '@aws-lambda-powertools/logger'; -{%- endif %} -{%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled"%} -import { Tracer } from '@aws-lambda-powertools/tracer'; -{%- endif %} - - -{%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Metrics"] == "enabled"%} -const metrics = new Metrics(); -{%- endif %} -{%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Logging"] == "enabled"%} -const logger = new Logger(); -{%- endif %} -{%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled"%} -const tracer = new Tracer(); -{%- endif %} - -/** - * - * Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format - * @param {APIGatewayProxyEvent} event - API Gateway Lambda Proxy Input Format - * @param {Context} object - API Gateway Lambda $context variable - * - * Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html - * @returns {APIGatewayProxyResult} object - API Gateway Lambda Proxy Output Format - * - */ - -export const lambdaHandler = async (event: APIGatewayProxyEvent, context: Context): Promise => { - let response: APIGatewayProxyResult; - - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Logging"] == "enabled"%} - - // Log the incoming event - logger.info('Lambda invocation event', { event }); - - // Append awsRequestId to each log statement - logger.appendKeys({ - awsRequestId: context.awsRequestId, - }); - - {%- endif %} - - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled"%} - // Get facade segment created by AWS Lambda - const segment = tracer.getSegment(); - - if (!segment) { - response = { - statusCode: 500, - body: "Failed to get segment" - } - return response; - } - - // Create subsegment for the function & set it as active - const handlerSegment = segment.addNewSubsegment(`## ${process.env._HANDLER}`); - tracer.setSegment(handlerSegment); - - // Annotate the subsegment with the cold start & serviceName - tracer.annotateColdStart(); - tracer.addServiceNameAnnotation(); - - // Add annotation for the awsRequestId - tracer.putAnnotation('awsRequestId', context.awsRequestId); - - {%- endif %} - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Metrics"] == "enabled" %} - // Capture cold start metrics - metrics.captureColdStartMetric(); - - {%- endif %} - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled"%} - // Create another subsegment & set it as active - const subsegment = handlerSegment.addNewSubsegment('### MySubSegment'); - tracer.setSegment(subsegment); - {%- endif %} - - try { - // hello world code - response = { - statusCode: 200, - body: JSON.stringify({ - message: 'hello world', - }), - }; - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Logging"] == "enabled"%} - logger.info(`Successful response from API enpoint: ${event.path}`, response.body); - {%- else %} - console.log('sending HTTP 200 - hello world response') - {%- endif %} - } catch (err) { - // Error handling - response = { - statusCode: 500, - body: JSON.stringify({ - message: 'some error happened', - }), - }; - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled"%} - tracer.addErrorAsMetadata(err as Error); - {%- endif %} - - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Logging"] == "enabled"%} - logger.error(`Error response from API enpoint: ${err}`, response.body); - {%- else %} - console.log('sending HTTP 500 - some error happened response') - {%- endif %} - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Metrics"] == "enabled" or cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled"%} - } finally { - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled"%} - // Close subsegments (the AWS Lambda one is closed automatically) - subsegment.close(); // (### MySubSegment) - handlerSegment.close(); // (## index.handler) - - // Set the facade segment as active again (the one created by AWS Lambda) - tracer.setSegment(segment); - - {%- endif %} - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Metrics"] == "enabled"%} - // Publish all stored metrics - metrics.publishStoredMetrics(); - - {%- endif %} - {%- endif %} - } - - return response; - -}; \ No newline at end of file diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/jest.config.ts b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/jest.config.ts deleted file mode 100644 index 3f8eb55bd..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/jest.config.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * For a detailed explanation regarding each configuration property and type check, visit: - * https://jestjs.io/docs/configuration - */ - -export default { - transform: { - '^.+\\.ts?$': 'ts-jest', - }, - clearMocks: true, - collectCoverage: true, - coverageDirectory: 'coverage', - coverageProvider: 'v8', - testMatch: ['**/tests/unit/*.test.ts'], -}; diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/package.json b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/package.json deleted file mode 100644 index aacc212dd..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "hello_world", - "version": "1.0.0", - "description": "hello world sample for NodeJS", - "main": "app.js", - "repository": "https://github.com/aws/aws-sam-cli-app-templates/tree/master/nodejs16.x/hello-ts-pt", - "author": "SAM CLI", - "license": "MIT", - "dependencies": { - "@aws-lambda-powertools/logger": "^2.0.3", - "@aws-lambda-powertools/metrics": "^2.0.3", - "@aws-lambda-powertools/tracer": "^2.0.3", - "esbuild": "^0.17.6" - }, - "scripts": { - "unit": "jest", - "lint": "eslint '*.ts' --quiet --fix", - "compile": "tsc", - "test": "npm run compile && npm run unit" - }, - "devDependencies": { - "@types/aws-lambda": "^8.10.109", - "@types/jest": "^29.4.0", - "@jest/globals": "^29.4.0", - "@types/node": "^18.13.0", - "@typescript-eslint/eslint-plugin": "^5.46.1", - "@typescript-eslint/parser": "^5.46.1", - "eslint": "^8.30.0", - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-prettier": "^4.0.0", - "jest": "^29.3.1", - "prettier": "^2.5.1", - "ts-jest": "^29.0.5", - "ts-node": "^10.9.1", - "typescript": "^4.9.4" - } -} diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.test.ts b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.test.ts deleted file mode 100644 index da70ae4da..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.test.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; -import { lambdaHandler } from '../../app'; -import { expect, describe, it } from '@jest/globals'; - -describe('Unit test for app handler', function () { - it('verifies successful response', async () => { - const event: APIGatewayProxyEvent = { - httpMethod: 'get', - body: '', - headers: {}, - isBase64Encoded: false, - multiValueHeaders: {}, - multiValueQueryStringParameters: {}, - path: '/hello', - pathParameters: {}, - queryStringParameters: {}, - requestContext: { - accountId: '123456789012', - apiId: '1234', - authorizer: {}, - httpMethod: 'get', - identity: { - accessKey: '', - accountId: '', - apiKey: '', - apiKeyId: '', - caller: '', - clientCert: { - clientCertPem: '', - issuerDN: '', - serialNumber: '', - subjectDN: '', - validity: { notAfter: '', notBefore: '' }, - }, - cognitoAuthenticationProvider: '', - cognitoAuthenticationType: '', - cognitoIdentityId: '', - cognitoIdentityPoolId: '', - principalOrgId: '', - sourceIp: '', - user: '', - userAgent: '', - userArn: '', - }, - path: '/hello', - protocol: 'HTTP/1.1', - requestId: 'c6af9ac6-7b61-11e6-9a41-93e8deadbeef', - requestTimeEpoch: 1428582896000, - resourceId: '123456', - resourcePath: '/hello', - stage: 'dev', - }, - resource: '', - stageVariables: {}, - }; - const context: Context = { - callbackWaitsForEmptyEventLoop: false, - functionName: 'lambdaHandler', - functionVersion: '1.0', - invokedFunctionArn: 'arn:1234567890:lambda:lambdaHandler', - memoryLimitInMB: '128', - awsRequestId: '1234567890', - logGroupName: 'lambdaHandlerLogGroup', - logStreamName: 'c6a789dff9326bc178', - getRemainingTimeInMillis: function (): number { - throw new Error('Function not implemented.'); - }, - done: function (error?: Error, result?: any): void { - throw new Error('Function not implemented.'); - }, - fail: function (error: string | Error): void { - throw new Error('Function not implemented.'); - }, - succeed: function (messageOrObject: any): void { - throw new Error('Function not implemented.'); - } - }; - const result: APIGatewayProxyResult = await lambdaHandler(event,context); - - expect(result.statusCode).toEqual(200); - expect(result.body).toEqual( - JSON.stringify({ - message: 'hello world', - }), - ); - }); -}); diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/tsconfig.json b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/tsconfig.json deleted file mode 100644 index 93fab7255..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/hello-world/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "compilerOptions": { - "target": "es2020", - "strict": true, - "preserveConstEnums": true, - "noEmit": true, - "sourceMap": false, - "module": "es2015", - "moduleResolution": "node", - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true - }, - "exclude": ["node_modules"], -} \ No newline at end of file diff --git a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index ede1fb2a5..000000000 --- a/nodejs16.x/hello-ts-pt/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,70 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - - Sample SAM Template for {{ cookiecutter.project_name }} - -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 3 - MemorySize: 128 - -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Properties: - CodeUri: hello-world/ - Handler: app.lambdaHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled"%} - Tracing: Active - {%- endif %} - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled" or cookiecutter["Powertools for AWS Lambda (TypeScript) Metrics"] == "enabled" or cookiecutter["Powertools for AWS Lambda (TypeScript) Logging"] == "enabled" %} - Environment: - Variables: - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Tracing"] == "enabled" or cookiecutter["Powertools for AWS Lambda (TypeScript) Metrics"] == "enabled"%} - POWERTOOLS_SERVICE_NAME: helloWorld - {%- endif %} - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Metrics"] == "enabled"%} - POWERTOOLS_METRICS_NAMESPACE: {{ cookiecutter.project_name|lower|replace(' ', '-') }} - {%- endif %} - {%- if cookiecutter["Powertools for AWS Lambda (TypeScript) Logging"] == "enabled"%} - LOG_LEVEL: INFO - {%- endif %} - {%- endif %} - Events: - HelloWorld: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: get - Metadata: # Manage esbuild properties - BuildMethod: esbuild - BuildProperties: - Minify: true - Target: "es2020" - # Sourcemap: true # Enabling source maps will create the required NODE_OPTIONS environment variables on your lambda function during sam build - EntryPoints: - - app.ts - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldApi: - Description: "API Gateway endpoint URL for Prod stage for Hello World function" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" - HelloWorldFunction: - Description: "Hello World Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn diff --git a/nodejs16.x/hello-ts/.gitignore b/nodejs16.x/hello-ts/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/hello-ts/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/hello-ts/README.md b/nodejs16.x/hello-ts/README.md deleted file mode 100644 index 58b01fe8a..000000000 --- a/nodejs16.x/hello-ts/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS TypeScript Hello-world for SAM based Serverless App - -A cookiecutter template to create a NodeJS TypeScript Hello world boilerplate using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x` - -> **NOTE**: ``--name`` allows you to specify a different project folder name (`sam-app` is the default) - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/hello-ts/cookiecutter.json b/nodejs16.x/hello-ts/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/hello-ts/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/hello-ts/setup.cfg b/nodejs16.x/hello-ts/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/hello-ts/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 5854f05ec..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1,207 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test -.env*.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Storybook build outputs -.out -.storybook-out -storybook-static - -# rollup.js default build output -dist/ - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# Temporary folders -tmp/ -temp/ - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/README.md b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 47e16f59f..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,127 +0,0 @@ -# {{ cookiecutter.project_name }} - -This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders. - -- hello-world - Code for the application's Lambda function written in TypeScript. -- events - Invocation events that you can use to invoke the function. -- hello-world/tests - Unit tests for the application code. -- template.yaml - A template that defines the application's AWS resources. - -The application uses several AWS resources, including Lambda functions and an API Gateway API. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started. - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the SAM CLI, you need the following tools. - -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the NPM package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -You can find your API Gateway Endpoint URL in the output values displayed after deployment. - -## Use the SAM CLI to build and test locally - -Build your application with the `sam build` command. - -```bash -{{ cookiecutter.project_name }}$ sam build -``` - -The SAM CLI installs dependencies defined in `hello-world/package.json`, compiles TypeScript with esbuild, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -{{ cookiecutter.project_name }}$ sam local invoke HelloWorldFunction --event events/event.json -``` - -The SAM CLI can also emulate your application's API. Use the `sam local start-api` to run the API locally on port 3000. - -```bash -{{ cookiecutter.project_name }}$ sam local start-api -{{ cookiecutter.project_name }}$ curl http://localhost:3000/ -``` - -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. - -```yaml - Events: - HelloWorld: - Type: Api - Properties: - Path: /hello - Method: get -``` - -## Add a resource to your application -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. - -## Fetch, tail, and filter Lambda function logs - -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. - -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. - -```bash -{{ cookiecutter.project_name }}$ sam logs -n HelloWorldFunction --stack-name {{ cookiecutter.project_name }} --tail -``` - -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). - -## Unit tests - -Tests are defined in the `hello-world/tests` folder in this project. Use NPM to install the [Jest test framework](https://jestjs.io/) and run unit tests. - -```bash -{{ cookiecutter.project_name }}$ cd hello-world -hello-world$ npm install -hello-world$ npm run test -``` - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -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. - -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/) diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/events/event.json b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/events/event.json deleted file mode 100644 index 070ad8e01..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/events/event.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "body": "{\"message\": \"hello world\"}", - "resource": "/{proxy+}", - "path": "/path/to/resource", - "httpMethod": "POST", - "isBase64Encoded": false, - "queryStringParameters": { - "foo": "bar" - }, - "pathParameters": { - "proxy": "/path/to/resource" - }, - "stageVariables": { - "baz": "qux" - }, - "headers": { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", - "Accept-Encoding": "gzip, deflate, sdch", - "Accept-Language": "en-US,en;q=0.8", - "Cache-Control": "max-age=0", - "CloudFront-Forwarded-Proto": "https", - "CloudFront-Is-Desktop-Viewer": "true", - "CloudFront-Is-Mobile-Viewer": "false", - "CloudFront-Is-SmartTV-Viewer": "false", - "CloudFront-Is-Tablet-Viewer": "false", - "CloudFront-Viewer-Country": "US", - "Host": "1234567890.execute-api.us-east-1.amazonaws.com", - "Upgrade-Insecure-Requests": "1", - "User-Agent": "Custom User Agent String", - "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", - "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", - "X-Forwarded-For": "127.0.0.1, 127.0.0.2", - "X-Forwarded-Port": "443", - "X-Forwarded-Proto": "https" - }, - "requestContext": { - "accountId": "123456789012", - "resourceId": "123456", - "stage": "prod", - "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", - "requestTime": "09/Apr/2015:12:34:56 +0000", - "requestTimeEpoch": 1428582896000, - "identity": { - "cognitoIdentityPoolId": null, - "accountId": null, - "cognitoIdentityId": null, - "caller": null, - "accessKey": null, - "sourceIp": "127.0.0.1", - "cognitoAuthenticationType": null, - "cognitoAuthenticationProvider": null, - "userArn": null, - "userAgent": "Custom User Agent String", - "user": null - }, - "path": "/prod/path/to/resource", - "resourcePath": "/{proxy+}", - "httpMethod": "POST", - "apiId": "1234567890", - "protocol": "HTTP/1.1" - } -} diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.eslintignore b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.eslintignore deleted file mode 100644 index 512d4cb8b..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -.aws-sam \ No newline at end of file diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.eslintrc.js b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.eslintrc.js deleted file mode 100644 index 5da871fc4..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.eslintrc.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - parser: "@typescript-eslint/parser", - parserOptions: { - ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features - sourceType: "module" - }, - extends: [ - "plugin:@typescript-eslint/recommended", // recommended rules from the @typescript-eslint/eslint-plugin - "plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. - ], - rules: { - // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs - // e.g. "@typescript-eslint/explicit-function-return-type": "off", - } - }; \ No newline at end of file diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.npmignore b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.prettierrc.js b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.prettierrc.js deleted file mode 100644 index 4c2c6c78b..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/.prettierrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - semi: true, - trailingComma: "all", - singleQuote: true, - printWidth: 120, - tabWidth: 4 - }; \ No newline at end of file diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/app.ts b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/app.ts deleted file mode 100644 index b4fb5e5c7..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/app.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'; - -/** - * - * Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format - * @param {Object} event - API Gateway Lambda Proxy Input Format - * - * Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html - * @returns {Object} object - API Gateway Lambda Proxy Output Format - * - */ - -export const lambdaHandler = async (event: APIGatewayProxyEvent): Promise => { - let response: APIGatewayProxyResult; - try { - response = { - statusCode: 200, - body: JSON.stringify({ - message: 'hello world', - }), - }; - } catch (err: unknown) { - console.error(err); - response = { - statusCode: 500, - body: JSON.stringify({ - message: err instanceof Error ? err.message : 'some error happened', - }), - }; - } - - return response; -}; diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/jest.config.ts b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/jest.config.ts deleted file mode 100644 index 3f8eb55bd..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/jest.config.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * For a detailed explanation regarding each configuration property and type check, visit: - * https://jestjs.io/docs/configuration - */ - -export default { - transform: { - '^.+\\.ts?$': 'ts-jest', - }, - clearMocks: true, - collectCoverage: true, - coverageDirectory: 'coverage', - coverageProvider: 'v8', - testMatch: ['**/tests/unit/*.test.ts'], -}; diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/package.json b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/package.json deleted file mode 100644 index 4a511d946..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/package.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "hello_world", - "version": "1.0.0", - "description": "hello world sample for NodeJS", - "main": "app.js", - "repository": "https://github.com/awslabs/aws-sam-cli/tree/develop/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs", - "author": "SAM CLI", - "license": "MIT", - "dependencies": { - "esbuild": "^0.14.14" - }, - "scripts": { - "unit": "jest", - "lint": "eslint '*.ts' --quiet --fix", - "compile": "tsc", - "test": "npm run compile && npm run unit" - }, - "devDependencies": { - "@types/aws-lambda": "^8.10.92", - "@types/jest": "^29.4.0", - "@jest/globals": "^29.2.0", - "@types/node": "^17.0.13", - "@typescript-eslint/eslint-plugin": "^5.10.2", - "@typescript-eslint/parser": "^5.10.2", - "eslint": "^8.8.0", - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-prettier": "^4.0.0", - "jest": "^29.3.1", - "prettier": "^2.5.1", - "ts-jest": "^29.0.5", - "ts-node": "^10.4.0", - "typescript": "^4.5.5" - } -} diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.test.ts b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.test.ts deleted file mode 100644 index f4501a905..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'; -import { lambdaHandler } from '../../app'; -import { expect, describe, it } from '@jest/globals'; - -describe('Unit test for app handler', function () { - it('verifies successful response', async () => { - const event: APIGatewayProxyEvent = { - httpMethod: 'get', - body: '', - headers: {}, - isBase64Encoded: false, - multiValueHeaders: {}, - multiValueQueryStringParameters: {}, - path: '/hello', - pathParameters: {}, - queryStringParameters: {}, - requestContext: { - accountId: '123456789012', - apiId: '1234', - authorizer: {}, - httpMethod: 'get', - identity: { - accessKey: '', - accountId: '', - apiKey: '', - apiKeyId: '', - caller: '', - clientCert: { - clientCertPem: '', - issuerDN: '', - serialNumber: '', - subjectDN: '', - validity: { notAfter: '', notBefore: '' }, - }, - cognitoAuthenticationProvider: '', - cognitoAuthenticationType: '', - cognitoIdentityId: '', - cognitoIdentityPoolId: '', - principalOrgId: '', - sourceIp: '', - user: '', - userAgent: '', - userArn: '', - }, - path: '/hello', - protocol: 'HTTP/1.1', - requestId: 'c6af9ac6-7b61-11e6-9a41-93e8deadbeef', - requestTimeEpoch: 1428582896000, - resourceId: '123456', - resourcePath: '/hello', - stage: 'dev', - }, - resource: '', - stageVariables: {}, - }; - const result: APIGatewayProxyResult = await lambdaHandler(event); - - expect(result.statusCode).toEqual(200); - expect(result.body).toEqual( - JSON.stringify({ - message: 'hello world', - }), - ); - }); -}); diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/tsconfig.json b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/tsconfig.json deleted file mode 100644 index ffaf193ea..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/hello-world/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "compilerOptions": { - "target": "es2020", - "strict": true, - "preserveConstEnums": true, - "noEmit": true, - "sourceMap": false, - "module":"es2015", - "moduleResolution":"node", - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - }, - "exclude": ["node_modules", "**/*.test.ts"] - } \ No newline at end of file diff --git a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index 62a806f22..000000000 --- a/nodejs16.x/hello-ts/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,54 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - - Sample SAM Template for {{ cookiecutter.project_name }} - -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 3 - MemorySize: 128 - -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Properties: - CodeUri: hello-world/ - Handler: app.lambdaHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Events: - HelloWorld: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: get - Metadata: # Manage esbuild properties - BuildMethod: esbuild - BuildProperties: - Minify: true - Target: "es2020" - # Sourcemap: true # Enabling source maps will create the required NODE_OPTIONS environment variables on your lambda function during sam build - EntryPoints: - - app.ts - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldApi: - Description: "API Gateway endpoint URL for Prod stage for Hello World function" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" - HelloWorldFunction: - Description: "Hello World Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn diff --git a/nodejs16.x/hello/.gitignore b/nodejs16.x/hello/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/hello/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/hello/README.md b/nodejs16.x/hello/README.md deleted file mode 100644 index 58d30fe93..000000000 --- a/nodejs16.x/hello/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS Hello-world for SAM based Serverless App - -A cookiecutter template to create a NodeJS Hello world boilerplate using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x` - -> **NOTE**: ``--name`` allows you to specify a different project folder name (`sam-app` is the default) - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/hello/cookiecutter.json b/nodejs16.x/hello/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/hello/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/hello/setup.cfg b/nodejs16.x/hello/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/hello/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/hello/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/hello/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 5854f05ec..000000000 --- a/nodejs16.x/hello/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1,207 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test -.env*.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Storybook build outputs -.out -.storybook-out -storybook-static - -# rollup.js default build output -dist/ - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# Temporary folders -tmp/ -temp/ - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam diff --git a/nodejs16.x/hello/{{cookiecutter.project_name}}/README.md b/nodejs16.x/hello/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 88490c00c..000000000 --- a/nodejs16.x/hello/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,127 +0,0 @@ -# {{ cookiecutter.project_name }} - -This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders. - -- hello-world - Code for the application's Lambda function. -- events - Invocation events that you can use to invoke the function. -- hello-world/tests - Unit tests for the application code. -- template.yaml - A template that defines the application's AWS resources. - -The application uses several AWS resources, including Lambda functions and an API Gateway API. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started. - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the SAM CLI, you need the following tools. - -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the NPM package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -You can find your API Gateway Endpoint URL in the output values displayed after deployment. - -## Use the SAM CLI to build and test locally - -Build your application with the `sam build` command. - -```bash -{{ cookiecutter.project_name }}$ sam build -``` - -The SAM CLI installs dependencies defined in `hello-world/package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -{{ cookiecutter.project_name }}$ sam local invoke HelloWorldFunction --event events/event.json -``` - -The SAM CLI can also emulate your application's API. Use the `sam local start-api` to run the API locally on port 3000. - -```bash -{{ cookiecutter.project_name }}$ sam local start-api -{{ cookiecutter.project_name }}$ curl http://localhost:3000/ -``` - -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. - -```yaml - Events: - HelloWorld: - Type: Api - Properties: - Path: /hello - Method: get -``` - -## Add a resource to your application -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. - -## Fetch, tail, and filter Lambda function logs - -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. - -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. - -```bash -{{ cookiecutter.project_name }}$ sam logs -n HelloWorldFunction --stack-name {{ cookiecutter.project_name }} --tail -``` - -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). - -## Unit tests - -Tests are defined in the `hello-world/tests` folder in this project. Use NPM to install the [Mocha test framework](https://mochajs.org/) and run unit tests. - -```bash -{{ cookiecutter.project_name }}$ cd hello-world -hello-world$ npm install -hello-world$ npm run test -``` - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -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. - -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/) diff --git a/nodejs16.x/hello/{{cookiecutter.project_name}}/events/event.json b/nodejs16.x/hello/{{cookiecutter.project_name}}/events/event.json deleted file mode 100644 index 070ad8e01..000000000 --- a/nodejs16.x/hello/{{cookiecutter.project_name}}/events/event.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "body": "{\"message\": \"hello world\"}", - "resource": "/{proxy+}", - "path": "/path/to/resource", - "httpMethod": "POST", - "isBase64Encoded": false, - "queryStringParameters": { - "foo": "bar" - }, - "pathParameters": { - "proxy": "/path/to/resource" - }, - "stageVariables": { - "baz": "qux" - }, - "headers": { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", - "Accept-Encoding": "gzip, deflate, sdch", - "Accept-Language": "en-US,en;q=0.8", - "Cache-Control": "max-age=0", - "CloudFront-Forwarded-Proto": "https", - "CloudFront-Is-Desktop-Viewer": "true", - "CloudFront-Is-Mobile-Viewer": "false", - "CloudFront-Is-SmartTV-Viewer": "false", - "CloudFront-Is-Tablet-Viewer": "false", - "CloudFront-Viewer-Country": "US", - "Host": "1234567890.execute-api.us-east-1.amazonaws.com", - "Upgrade-Insecure-Requests": "1", - "User-Agent": "Custom User Agent String", - "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", - "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", - "X-Forwarded-For": "127.0.0.1, 127.0.0.2", - "X-Forwarded-Port": "443", - "X-Forwarded-Proto": "https" - }, - "requestContext": { - "accountId": "123456789012", - "resourceId": "123456", - "stage": "prod", - "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", - "requestTime": "09/Apr/2015:12:34:56 +0000", - "requestTimeEpoch": 1428582896000, - "identity": { - "cognitoIdentityPoolId": null, - "accountId": null, - "cognitoIdentityId": null, - "caller": null, - "accessKey": null, - "sourceIp": "127.0.0.1", - "cognitoAuthenticationType": null, - "cognitoAuthenticationProvider": null, - "userArn": null, - "userAgent": "Custom User Agent String", - "user": null - }, - "path": "/prod/path/to/resource", - "resourcePath": "/{proxy+}", - "httpMethod": "POST", - "apiId": "1234567890", - "protocol": "HTTP/1.1" - } -} diff --git a/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/.npmignore b/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/app.js b/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/app.js deleted file mode 100644 index 695d1b567..000000000 --- a/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/app.js +++ /dev/null @@ -1,33 +0,0 @@ -// const axios = require('axios') -// const url = 'http://checkip.amazonaws.com/'; -let response; - -/** - * - * Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format - * @param {Object} event - API Gateway Lambda Proxy Input Format - * - * Context doc: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html - * @param {Object} context - * - * Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html - * @returns {Object} object - API Gateway Lambda Proxy Output Format - * - */ -exports.lambdaHandler = async (event, context) => { - try { - // const ret = await axios(url); - response = { - 'statusCode': 200, - 'body': JSON.stringify({ - message: 'hello world', - // location: ret.data.trim() - }) - } - } catch (err) { - console.log(err); - return err; - } - - return response -}; diff --git a/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/package.json b/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/package.json deleted file mode 100644 index 2605186e0..000000000 --- a/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "hello_world", - "version": "1.0.0", - "description": "hello world sample for NodeJS", - "main": "app.js", - "repository": "https://github.com/awslabs/aws-sam-cli/tree/develop/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs", - "author": "SAM CLI", - "license": "MIT", - "dependencies": { - "axios": ">=1.6.0" - }, - "scripts": { - "test": "mocha tests/unit/" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^9.1.4" - } -} diff --git a/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.js b/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.js deleted file mode 100644 index ae94b9f2f..000000000 --- a/nodejs16.x/hello/{{cookiecutter.project_name}}/hello-world/tests/unit/test-handler.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -const app = require('../../app.js'); -const chai = require('chai'); -const expect = chai.expect; -var event, context; - -describe('Tests index', function () { - it('verifies successful response', async () => { - const result = await app.lambdaHandler(event, context) - - expect(result).to.be.an('object'); - expect(result.statusCode).to.equal(200); - expect(result.body).to.be.an('string'); - - let response = JSON.parse(result.body); - - expect(response).to.be.an('object'); - expect(response.message).to.be.equal("hello world"); - // expect(response.location).to.be.an("string"); - }); -}); diff --git a/nodejs16.x/hello/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/hello/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index cf8443aa9..000000000 --- a/nodejs16.x/hello/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,46 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - - Sample SAM Template for {{ cookiecutter.project_name }} - -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 3 - MemorySize: 128 - -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Properties: - CodeUri: hello-world/ - Handler: app.lambdaHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Events: - HelloWorld: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: get - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldApi: - Description: "API Gateway endpoint URL for Prod stage for Hello World function" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" - HelloWorldFunction: - Description: "Hello World Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn diff --git a/nodejs16.x/response-streaming/.gitignore b/nodejs16.x/response-streaming/.gitignore deleted file mode 100644 index 41b1156d3..000000000 --- a/nodejs16.x/response-streaming/.gitignore +++ /dev/null @@ -1,208 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test -.env*.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Storybook build outputs -.out -.storybook-out -storybook-static - -# rollup.js default build output -dist/ - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# Temporary folders -tmp/ -temp/ - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam diff --git a/nodejs16.x/response-streaming/README.md b/nodejs16.x/response-streaming/README.md deleted file mode 100644 index 58d30fe93..000000000 --- a/nodejs16.x/response-streaming/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS Hello-world for SAM based Serverless App - -A cookiecutter template to create a NodeJS Hello world boilerplate using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x` - -> **NOTE**: ``--name`` allows you to specify a different project folder name (`sam-app` is the default) - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/response-streaming/cookiecutter.json b/nodejs16.x/response-streaming/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/response-streaming/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/response-streaming/setup.cfg b/nodejs16.x/response-streaming/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/response-streaming/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 41b1156d3..000000000 --- a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1,208 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test -.env*.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Storybook build outputs -.out -.storybook-out -storybook-static - -# rollup.js default build output -dist/ - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# Temporary folders -tmp/ -temp/ - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam diff --git a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/README.md b/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index f7cd80b81..000000000 --- a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,102 +0,0 @@ -# {{cookiecutter.project_name}} - -This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) command line interface (CLI). It includes the following files and folders: - -- `src` - Code for the application's Lambda function. -- `template.yaml` - A template that defines the application's AWS resources. -- `__tests__` - Unit tests for the application code. - -Resources for this project are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open-source plugin for popular IDEs that uses the AWS SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds step-through debugging for Lambda function code. - -To get started, see the following: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The AWS SAM CLI is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the AWS SAM CLI, you need the following tools: - -* AWS SAM CLI - [Install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html). -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the npm package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community). - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -## Building and testing - -Build your application by using the `sam build` command. - -```bash -my-application$ sam build -``` - -The AWS SAM CLI installs dependencies that are defined in `package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -my-application$ sam local invoke StreamingFunction --no-event -``` - -The streaming capabilities of the function are present only when invoked through a Function URL, so the response won't be streamed when invoking locally. To learn more, see the [Lambda response streaming documentation](https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html) - -There are also unit tests inside the `__tests__` directory, that can be run using `npm run test`. - - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, the AWS SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs that are generated by your 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. - -**NOTE:** This command works for all Lambda functions, not just the ones you deploy using AWS SAM. - -```bash -my-application$ sam logs -n StreamingFunction --stack-name sam-app --tail -``` - -**NOTE:** This uses the logical name of the function within the stack. This is the correct name to use when searching logs inside an AWS Lambda function within a CloudFormation stack, even if the deployed function name varies due to CloudFormation's unique resource name generation. - -You can find more information and examples about filtering Lambda function logs in the [AWS SAM CLI documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Cleanup - -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: - -```bash -sam delete -``` - -## Resources - -For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the [AWS SAM Developer Guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html). - -Next, you can use the AWS Serverless Application Repository to deploy ready-to-use apps that go beyond Hello World samples and learn how authors developed their applications. For more information, see the [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) and the [AWS Serverless Application Repository Developer Guide](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html). diff --git a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/__tests__/unit/index.test.js b/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/__tests__/unit/index.test.js deleted file mode 100644 index 134a63ca0..000000000 --- a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/__tests__/unit/index.test.js +++ /dev/null @@ -1,41 +0,0 @@ -// `awslambda` object doesn't exist outside of the Lambda runtime, so we mock its definitions here -awslambda = { - streamifyResponse: _streamifyResponseMock, - HttpResponseStream: { from: _responseStreamMock }, -}; - -const { handler } = require('../../src/index.js'); - -// This includes all tests for handler() -describe('Test for streaming handler', function () { - // This test invokes handler() and compare the values streamed - it('Verifies successful response', async () => { - const responseStream = { - setContentType: jest.fn(), - write: jest.fn(), - end: jest.fn(), - } - // Invoke handler() - await handler({}, responseStream); - - // Check some of the text that was streamed from your Lambda function. - const expectedResults = ['', '

First write!

', '']; - // Compare the result with the expected result - expect(responseStream.write).toHaveBeenCalledWith(expectedResults[0]); - expect(responseStream.write).toHaveBeenCalledWith(expectedResults[1]); - expect(responseStream.write).toHaveBeenLastCalledWith(expectedResults[2]); - expect(responseStream.end).toHaveBeenCalledTimes(1); - }); -}); - -function _streamifyResponseMock(lambdaHandler) { - return lambdaHandler; -} - -function _responseStreamMock(responseStream, httpResponseMetadata){ - responseStream.setContentType("vnd.awslambda.http-integration-response"); - responseStream.write(httpResponseMetadata); - // Separator between metadata and the body - responseStream.write("\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"); - return responseStream; -} \ No newline at end of file diff --git a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/package.json b/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/package.json deleted file mode 100644 index e8ce5fb99..000000000 --- a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "streaming-function", - "description": "Sample project for Lambda streaming invoke", - "version": "0.0.1", - "private": true, - "devDependencies": { - "jest": "^29.2.1" - }, - "scripts": { - "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js" - }, - "jest": { - "testMatch": [ - "**/__tests__/**/*.[jt]s?(x)", - "**/?(*.)+(spec|test).[jt]s?(x)", - "**/__tests__/**/*.mjs?(x)", - "**/?(*.)+(spec|test).mjs?(x)" - ], - "moduleFileExtensions": [ - "mjs", - "js" - ] - } -} diff --git a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/src/index.js b/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/src/index.js deleted file mode 100644 index 71ae27051..000000000 --- a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/src/index.js +++ /dev/null @@ -1,33 +0,0 @@ -exports.handler = awslambda.streamifyResponse( - async (event, responseStream, context) => { - const httpResponseMetadata = { - statusCode: 200, - headers: { - "Content-Type": "text/html", - "X-Custom-Header": "Example-Custom-Header" - } - }; - - responseStream = awslambda.HttpResponseStream.from(responseStream, httpResponseMetadata); - // It's recommended to use a `pipeline` over the `write` method for more complex use cases. - // Learn more: https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html - responseStream.write(""); - responseStream.write("

First write!

"); - - responseStream.write("

Streaming h1

"); - await new Promise(r => setTimeout(r, 1000)); - responseStream.write("

Streaming h2

"); - await new Promise(r => setTimeout(r, 1000)); - responseStream.write("

Streaming h3

"); - await new Promise(r => setTimeout(r, 1000)); - - // Long strings will be streamed - const loremIpsum1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae mi tincidunt tellus ultricies dignissim id et diam. Morbi pharetra eu nisi et finibus. Vivamus diam nulla, vulputate et nisl cursus, pellentesque vehicula libero. Cras imperdiet lorem ante, non posuere dolor sollicitudin a. Vestibulum ipsum lacus, blandit nec augue id, lobortis dictum urna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Morbi auctor orci eget tellus aliquam, non maximus massa porta. In diam ante, pulvinar aliquam nisl non, elementum hendrerit sapien. Vestibulum massa nunc, mattis non congue vitae, placerat in quam. Nam vulputate lectus metus, et dignissim erat varius a."; - responseStream.write(`

${loremIpsum1}

`); - await new Promise(r => setTimeout(r, 1000)); - - responseStream.write("

DONE!

"); - responseStream.write(""); - responseStream.end(); - } -); diff --git a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index aaf7281fd..000000000 --- a/nodejs16.x/response-streaming/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,33 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 - -Description: > - Sample SAM Template for {{ cookiecutter.project_name }} - -Resources: - StreamingFunction: - Type: AWS::Serverless::Function - Properties: - CodeUri: src/ - Handler: index.handler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Timeout: 10 - FunctionUrlConfig: - AuthType: AWS_IAM - InvokeMode: RESPONSE_STREAM - -Outputs: - StreamingFunction: - Description: "Streaming Lambda Function ARN" - Value: !GetAtt StreamingFunction.Arn - StreamingFunctionURL: - Description: "Streaming Lambda Function URL" - Value: !GetAtt StreamingFunctionUrl.FunctionUrl - - diff --git a/nodejs16.x/s3/.gitignore b/nodejs16.x/s3/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/s3/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/s3/README.md b/nodejs16.x/s3/README.md deleted file mode 100644 index f1ab78a0b..000000000 --- a/nodejs16.x/s3/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS S3 Quick Start Application - -A cookiecutter template to create a NodeJS S3 Quick Start Application using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x --app-template quick-start-s3 --name s3-app` - -> **NOTE**: ``--name`` allows you to specify a different project folder name - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/s3/cookiecutter.json b/nodejs16.x/s3/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/s3/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/s3/setup.cfg b/nodejs16.x/s3/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/s3/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/s3/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/s3/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 2d980704f..000000000 --- a/nodejs16.x/s3/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.aws-sam -node_modules \ No newline at end of file diff --git a/nodejs16.x/s3/{{cookiecutter.project_name}}/README.md b/nodejs16.x/s3/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index d0bffbd56..000000000 --- a/nodejs16.x/s3/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,151 +0,0 @@ -# {{cookiecutter.project_name}} - -This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) command line interface (CLI). It includes the following files and folders: - -- `src` - Code for the application's Lambda function. -- `events` - Invocation events that you can use to invoke the function. -- `__tests__` - Unit tests for the application code. -- `template.yaml` - A template that defines the application's AWS resources. - -Resources for this project are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open-source plugin for popular IDEs that uses the AWS SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds step-through debugging for Lambda function code. - -To get started, see the following: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The AWS SAM CLI is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the AWS SAM CLI, you need the following tools: - -* AWS SAM CLI - [Install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html). -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the npm package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community). - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **Parameter AppBucketName**: This template includes a parameter to name the S3 bucket you will create as a part of the new application. This name needs to be globally unique. -* **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. -* **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. -* **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. - -## Use the AWS SAM CLI to build and test locally - -Build your application by using the `sam build` command. - -```bash -my-application$ sam build -``` - -The AWS SAM CLI installs dependencies that are defined in `package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -my-application$ sam local invoke S3JsonLoggerFunction --event events/event-s3.json -``` - -## Add a resource to your application - -The application template uses 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 that aren't included in the [AWS SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use the standard [AWS CloudFormation resource types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html). - -Update `template.yaml` to add a dead-letter queue to your application. In the **Resources** section, add a resource named **MyQueue** with the type **AWS::SQS::Queue**. Then add a property to the **AWS::Serverless::Function** resource named **DeadLetterQueue** that targets the queue's Amazon Resource Name (ARN), and a policy that grants the function permission to access the queue. - -``` -Resources: - MyQueue: - Type: AWS::SQS::Queue - S3JsonLoggerFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/s3-json-logger.s3JsonLoggerHandler - Runtime: nodejs16.x - DeadLetterQueue: - Type: SQS - TargetArn: !GetAtt MyQueue.Arn - Policies: - - SQSSendMessagePolicy: - QueueName: !GetAtt MyQueue.QueueName - - S3NewObjectEvent: - Type: S3 - Properties: - Bucket: !Ref AppBucket - Events: s3:ObjectCreated:* - Filter: - S3Key: - Rules: - - Name: suffix - Value: ".json" -``` - -The dead-letter queue is a location for Lambda to send events that could not be processed. It's only used if you invoke your function asynchronously, but it's useful here to show how you can modify your application's resources and function configuration. - -Deploy the updated application. - -```bash -my-application$ sam deploy -``` - -Open the [**Applications**](https://console.aws.amazon.com/lambda/home#/applications) page of the Lambda console, and choose your application. When the deployment completes, view the application resources on the **Overview** tab to see the new resource. Then, choose the function to see the updated configuration that specifies the dead-letter queue. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, the AWS SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs that are generated by your 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. - -**NOTE:** This command works for all Lambda functions, not just the ones you deploy using AWS SAM. - -```bash -my-application$ sam logs -n S3JsonLoggerFunction --stack-name sam-app --tail -``` - -**NOTE:** This uses the logical name of the function within the stack. This is the correct name to use when searching logs inside an AWS Lambda function within a CloudFormation stack, even if the deployed function name varies due to CloudFormation's unique resource name generation. - -You can find more information and examples about filtering Lambda function logs in the [AWS SAM CLI documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -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. - -```bash -my-application$ npm install -my-application$ npm run test -``` - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the [AWS SAM Developer Guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html). - -Next, you can use the AWS Serverless Application Repository to deploy ready-to-use apps that go beyond Hello World samples and learn how authors developed their applications. For more information, see the [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) and the [AWS Serverless Application Repository Developer Guide](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html). diff --git a/nodejs16.x/s3/{{cookiecutter.project_name}}/__tests__/unit/handlers/s3-json-logger-handler.test.js b/nodejs16.x/s3/{{cookiecutter.project_name}}/__tests__/unit/handlers/s3-json-logger-handler.test.js deleted file mode 100644 index 5df85a7ff..000000000 --- a/nodejs16.x/s3/{{cookiecutter.project_name}}/__tests__/unit/handlers/s3-json-logger-handler.test.js +++ /dev/null @@ -1,37 +0,0 @@ -const AWS = require('aws-sdk-mock'); - -describe('Test s3JsonLoggerHandler', () => { - it('should read and log S3 objects', async () => { - const objectBody = '{"Test": "PASS"}'; - const getObjectResp = { - Body: objectBody - }; - - AWS.mock('S3', 'getObject', function(params, callback) { - callback(null, getObjectResp); - }); - - const event = { - Records: [ - { - s3: { - bucket: { - name: "test-bucket" - }, - object: { - key: "test-key" - } - } - } - ] - } - - console.info = jest.fn(); - let handler = require('../../../src/handlers/s3-json-logger.js'); - - await handler.s3JsonLoggerHandler(event, null); - - expect(console.info).toHaveBeenCalledWith(objectBody); - AWS.restore('S3'); - }); -}); diff --git a/nodejs16.x/s3/{{cookiecutter.project_name}}/buildspec.yml b/nodejs16.x/s3/{{cookiecutter.project_name}}/buildspec.yml deleted file mode 100644 index 7c1dae85e..000000000 --- a/nodejs16.x/s3/{{cookiecutter.project_name}}/buildspec.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: 0.2 -phases: - install: - commands: - # Install all dependencies (including dependencies for running tests) - - npm install - pre_build: - commands: - # Discover and run unit tests in the '__tests__' directory - - npm run test - # Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda - - rm -rf ./__tests__ - # Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json) - - npm prune --production - build: - commands: - # Use AWS SAM to package the application by using AWS CloudFormation - - aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --output-template template-export.yml -artifacts: - type: zip - files: - - template-export.yml diff --git a/nodejs16.x/s3/{{cookiecutter.project_name}}/events/event-s3.json b/nodejs16.x/s3/{{cookiecutter.project_name}}/events/event-s3.json deleted file mode 100644 index b13b216d2..000000000 --- a/nodejs16.x/s3/{{cookiecutter.project_name}}/events/event-s3.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "Records": [ - { - "eventVersion": "2.0", - "eventSource": "aws:s3", - "awsRegion": "us-east-1", - "eventTime": "1970-01-01T00:00:00.000Z", - "eventName": "ObjectCreated:Put", - "userIdentity": { - "principalId": "EXAMPLE" - }, - "requestParameters": { - "sourceIPAddress": "127.0.0.1" - }, - "responseElements": { - "x-amz-request-id": "EXAMPLE123456789", - "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH" - }, - "s3": { - "s3SchemaVersion": "1.0", - "configurationId": "testConfigRule", - "bucket": { - "name": "example-bucket", - "ownerIdentity": { - "principalId": "EXAMPLE" - }, - "arn": "arn:aws:s3:::example-bucket" - }, - "object": { - "key": "test/key", - "size": 1024, - "eTag": "0123456789abcdef0123456789abcdef", - "sequencer": "0A1B2C3D4E5F678901" - } - } - } - ] -} diff --git a/nodejs16.x/s3/{{cookiecutter.project_name}}/package.json b/nodejs16.x/s3/{{cookiecutter.project_name}}/package.json deleted file mode 100644 index ad0ca373b..000000000 --- a/nodejs16.x/s3/{{cookiecutter.project_name}}/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "replaced-by-user-input", - "description": "replaced-by-user-input", - "version": "0.0.1", - "private": true, - "dependencies": { - "aws-sdk": "^2.799.0" - }, - "devDependencies": { - "jest": "^26.6.3", - "aws-sdk-mock": "^5.1.0" - }, - "scripts": { - "test": "jest" - } -} diff --git a/nodejs16.x/s3/{{cookiecutter.project_name}}/src/handlers/s3-json-logger.js b/nodejs16.x/s3/{{cookiecutter.project_name}}/src/handlers/s3-json-logger.js deleted file mode 100644 index caa878ba0..000000000 --- a/nodejs16.x/s3/{{cookiecutter.project_name}}/src/handlers/s3-json-logger.js +++ /dev/null @@ -1,26 +0,0 @@ -const AWS = require('aws-sdk'); - -const s3 = new AWS.S3(); - -/** - * A Lambda function that logs the payload received from S3. - */ -exports.s3JsonLoggerHandler = async (event, context) => { - // All log statements are written to CloudWatch by default. For more information, see - // https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-logging.html - const getObjectRequests = event.Records.map(record => { - const params = { - Bucket: record.s3.bucket.name, - Key: record.s3.object.key - }; - return s3.getObject(params).promise().then(data => { - console.info(data.Body.toString()); - }).catch(err => { - console.error("Error calling S3 getObject:", err); - return Promise.reject(err); - }) - }); - return Promise.all(getObjectRequests).then(() => { - //console.debug('Complete!'); - }); -}; diff --git a/nodejs16.x/s3/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/s3/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index 121c37b09..000000000 --- a/nodejs16.x/s3/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,47 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - {{cookiecutter.project_name}} - -Parameters: - AppBucketName: - Type: String - Description: "REQUIRED: Unique S3 bucket name to use for the app." - -Resources: - S3JsonLoggerFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/s3-json-logger.s3JsonLoggerHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - MemorySize: 128 - Timeout: 60 - Policies: - S3ReadPolicy: - BucketName: !Ref AppBucketName - Events: - S3NewObjectEvent: - Type: S3 - Properties: - Bucket: !Ref AppBucket - Events: s3:ObjectCreated:* - Filter: - S3Key: - Rules: - - Name: suffix - Value: ".json" - AppBucket: - Type: AWS::S3::Bucket - Properties: - BucketName: !Ref AppBucketName - BucketEncryption: - ServerSideEncryptionConfiguration: - - BucketKeyEnabled: true - VersioningConfiguration: - Status: Enabled diff --git a/nodejs16.x/scratch/.gitignore b/nodejs16.x/scratch/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/scratch/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/scratch/README.md b/nodejs16.x/scratch/README.md deleted file mode 100644 index fcd78ae0c..000000000 --- a/nodejs16.x/scratch/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS "From Scratch" Quick Start Application - -A cookiecutter template to create a NodeJS Basic Quick Start Application using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x --app-template quick-start-from-scratch --name sam-app` - -> **NOTE**: ``--name`` allows you to specify a different project folder name - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/scratch/cookiecutter.json b/nodejs16.x/scratch/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/scratch/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/scratch/setup.cfg b/nodejs16.x/scratch/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/scratch/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/scratch/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/scratch/{{cookiecutter.project_name}}/.gitignore deleted file mode 100755 index b512c09d4..000000000 --- a/nodejs16.x/scratch/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff --git a/nodejs16.x/scratch/{{cookiecutter.project_name}}/README.md b/nodejs16.x/scratch/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index b835d33fa..000000000 --- a/nodejs16.x/scratch/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,140 +0,0 @@ -# {{cookiecutter.project_name}} - -This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) command line interface (CLI). It includes the following files and folders: - -- `src` - Code for the application's Lambda function. -- `events` - Invocation events that you can use to invoke the function. -- `__tests__` - Unit tests for the application code. -- `template.yaml` - A template that defines the application's AWS resources. - -Resources for this project are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open-source plugin for popular IDEs that uses the AWS SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds step-through debugging for Lambda function code. - -To get started, see the following: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The AWS SAM CLI is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the AWS SAM CLI, you need the following tools: - -* AWS SAM CLI - [Install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html). -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the npm package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community). - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -## Use the AWS SAM CLI to build and test locally - -Build your application by using the `sam build` command. - -```bash -my-application$ sam build -``` - -The AWS SAM CLI installs dependencies that are defined in `package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -my-application$ sam local invoke helloFromLambdaFunction --no-event -``` - -## Add a resource to your application - -The application template uses 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 that aren't included in the [AWS SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use the standard [AWS CloudFormation resource types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html). - -Update `template.yaml` to add a dead-letter queue to your application. In the **Resources** section, add a resource named **MyQueue** with the type **AWS::SQS::Queue**. Then add a property to the **AWS::Serverless::Function** resource named **DeadLetterQueue** that targets the queue's Amazon Resource Name (ARN), and a policy that grants the function permission to access the queue. - -``` -Resources: - MyQueue: - Type: AWS::SQS::Queue - helloFromLambdaFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/hello-from-lambda.helloFromLambdaHandler - Runtime: nodejs16.x - DeadLetterQueue: - Type: SQS - TargetArn: !GetAtt MyQueue.Arn - Policies: - - SQSSendMessagePolicy: - QueueName: !GetAtt MyQueue.QueueName -``` - -The dead-letter queue is a location for Lambda to send events that could not be processed. It's only used if you invoke your function asynchronously, but it's useful here to show how you can modify your application's resources and function configuration. - -Deploy the updated application. - -```bash -my-application$ sam deploy -``` - -Open the [**Applications**](https://console.aws.amazon.com/lambda/home#/applications) page of the Lambda console, and choose your application. When the deployment completes, view the application resources on the **Overview** tab to see the new resource. Then, choose the function to see the updated configuration that specifies the dead-letter queue. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, the AWS SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs that are generated by your 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. - -**NOTE:** This command works for all Lambda functions, not just the ones you deploy using AWS SAM. - -```bash -my-application$ sam logs -n helloFromLambdaFunction --stack-name sam-app --tail -``` - -**NOTE:** This uses the logical name of the function within the stack. This is the correct name to use when searching logs inside an AWS Lambda function within a CloudFormation stack, even if the deployed function name varies due to CloudFormation's unique resource name generation. - -You can find more information and examples about filtering Lambda function logs in the [AWS SAM CLI documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -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. - -```bash -my-application$ npm install -my-application$ npm run test -``` - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the [AWS SAM Developer Guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html). - -Next, you can use the AWS Serverless Application Repository to deploy ready-to-use apps that go beyond Hello World samples and learn how authors developed their applications. For more information, see the [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) and the [AWS Serverless Application Repository Developer Guide](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html). diff --git a/nodejs16.x/scratch/{{cookiecutter.project_name}}/__tests__/unit/handlers/hello-from-lambda.test.js b/nodejs16.x/scratch/{{cookiecutter.project_name}}/__tests__/unit/handlers/hello-from-lambda.test.js deleted file mode 100644 index 4d177f1db..000000000 --- a/nodejs16.x/scratch/{{cookiecutter.project_name}}/__tests__/unit/handlers/hello-from-lambda.test.js +++ /dev/null @@ -1,20 +0,0 @@ -// Import all functions from hello-from-lambda.js -const lambda = require('../../../src/handlers/hello-from-lambda.js'); - -// This includes all tests for helloFromLambdaHandler() -describe('Test for hello-from-lambda', function () { - // This test invokes helloFromLambdaHandler() and compare the result - it('Verifies successful response', async () => { - // Invoke helloFromLambdaHandler() - const result = await lambda.helloFromLambdaHandler(); - /* - The expected result should match the return from your Lambda function. - e.g. - if you change from `const message = 'Hello from Lambda!';` to `const message = 'Hello World!';` in hello-from-lambda.js - you should change the following line to `const expectedResult = 'Hello World!';` - */ - const expectedResult = 'Hello from Lambda!'; - // Compare the result with the expected result - expect(result).toEqual(expectedResult); - }); -}); diff --git a/nodejs16.x/scratch/{{cookiecutter.project_name}}/buildspec.yml b/nodejs16.x/scratch/{{cookiecutter.project_name}}/buildspec.yml deleted file mode 100755 index 86e7a9ebf..000000000 --- a/nodejs16.x/scratch/{{cookiecutter.project_name}}/buildspec.yml +++ /dev/null @@ -1,25 +0,0 @@ -version: 0.2 - -phases: - install: - commands: - # Install all dependencies (including dependencies for running tests) - - npm install - pre_build: - commands: - # Discover and run unit tests in the '__tests__' directory - - npm run test - # Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda - - rm -rf ./__tests__ - # Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json) - - npm prune --production - build: - commands: - # Use AWS SAM to package the application by using AWS CloudFormation - - aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --output-template template-export.yml -artifacts: - type: zip - files: - - template-export.yml - - diff --git a/nodejs16.x/scratch/{{cookiecutter.project_name}}/package.json b/nodejs16.x/scratch/{{cookiecutter.project_name}}/package.json deleted file mode 100755 index 57ccc5af5..000000000 --- a/nodejs16.x/scratch/{{cookiecutter.project_name}}/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "replaced-by-user-input", - "description": "replaced-by-user-input", - "version": "0.0.1", - "private": true, - "dependencies": {}, - "devDependencies": { - "jest": "^26.6.3" - }, - "scripts": { - "test": "jest" - } -} diff --git a/nodejs16.x/scratch/{{cookiecutter.project_name}}/src/handlers/hello-from-lambda.js b/nodejs16.x/scratch/{{cookiecutter.project_name}}/src/handlers/hello-from-lambda.js deleted file mode 100755 index aedf369dc..000000000 --- a/nodejs16.x/scratch/{{cookiecutter.project_name}}/src/handlers/hello-from-lambda.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * A Lambda function that returns a static string - */ -exports.helloFromLambdaHandler = async () => { - // If you change this message, you will need to change hello-from-lambda.test.js - const message = 'Hello from Lambda!'; - - // All log statements are written to CloudWatch - console.info(`${message}`); - - return message; -} diff --git a/nodejs16.x/scratch/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/scratch/{{cookiecutter.project_name}}/template.yaml deleted file mode 100755 index d8c6696e2..000000000 --- a/nodejs16.x/scratch/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,38 +0,0 @@ -# This is the SAM template that represents the architecture of your serverless application -# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html - -# The AWSTemplateFormatVersion identifies the capabilities of the template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html -AWSTemplateFormatVersion: 2010-09-09 -Description: >- - {{cookiecutter.project_name}} - -# Transform section specifies one or more macros that AWS CloudFormation uses to process your template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html -Transform: -- AWS::Serverless-2016-10-31 - -# Resources declares the AWS resources that you want to include in the stack -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html -Resources: - # Each Lambda function is defined by properties: - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - - # This is a Lambda function config associated with the source code: hello-from-lambda.js - helloFromLambdaFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/hello-from-lambda.helloFromLambdaHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - MemorySize: 128 - Timeout: 100 - Description: A Lambda function that returns a static string. - Policies: - # Give Lambda basic execution Permission to the helloFromLambda - - AWSLambdaBasicExecutionRole diff --git a/nodejs16.x/sns/.gitignore b/nodejs16.x/sns/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/sns/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/sns/README.md b/nodejs16.x/sns/README.md deleted file mode 100644 index dc62ba614..000000000 --- a/nodejs16.x/sns/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS SNS Quick Start Application - -A cookiecutter template to create a NodeJS SNS Quick Start Application using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x --app-template quick-start-sns --name sns-app` - -> **NOTE**: ``--name`` allows you to specify a different project folder name - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/sns/cookiecutter.json b/nodejs16.x/sns/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/sns/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/sns/setup.cfg b/nodejs16.x/sns/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/sns/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/sns/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/sns/{{cookiecutter.project_name}}/.gitignore deleted file mode 100755 index b512c09d4..000000000 --- a/nodejs16.x/sns/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff --git a/nodejs16.x/sns/{{cookiecutter.project_name}}/README.md b/nodejs16.x/sns/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 4d86bb5ee..000000000 --- a/nodejs16.x/sns/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,146 +0,0 @@ -# {{cookiecutter.project_name}} - -This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) command line interface (CLI). It includes the following files and folders: - -- `src` - Code for the application's Lambda function. -- `events` - Invocation events that you can use to invoke the function. -- `__tests__` - Unit tests for the application code. -- `template.yaml` - A template that defines the application's AWS resources. - -Resources for this project are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open-source plugin for popular IDEs that uses the AWS SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds step-through debugging for Lambda function code. - -To get started, see the following: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The AWS SAM CLI is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the AWS SAM CLI, you need the following tools: - -* AWS SAM CLI - [Install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html). -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the npm package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community). - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -## Use the AWS SAM CLI to build and test locally - -Build your application by using the `sam build` command. - -```bash -my-application$ sam build -``` - -The AWS SAM CLI installs dependencies that are defined in `package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -my-application$ sam local invoke SNSPayloadLogger --event events/event-sns.json -``` - -## Add a resource to your application - -The application template uses 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 that aren't included in the [AWS SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use the standard [AWS CloudFormation resource types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html). - -Update `template.yaml` to add a dead-letter queue to your application. In the **Resources** section, add a resource named **MyQueue** with the type **AWS::SQS::Queue**. Then add a property to the **AWS::Serverless::Function** resource named **DeadLetterQueue** that targets the queue's Amazon Resource Name (ARN), and a policy that grants the function permission to access the queue. - -``` -Resources: - MyQueue: - Type: AWS::SQS::Queue - SNSPayloadLogger: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/sns-payload-logger.snsPayloadLoggerHandler - Runtime: nodejs16.x - DeadLetterQueue: - Type: SQS - TargetArn: !GetAtt MyQueue.Arn - Policies: - - SQSSendMessagePolicy: - QueueName: !GetAtt MyQueue.QueueName -``` - -The dead-letter queue is a location for Lambda to send events that could not be processed. It's only used if you invoke your function asynchronously, but it's useful here to show how you can modify your application's resources and function configuration. - -Deploy the updated application. - -```bash -my-application$ sam package \ - --output-template-file packaged.yaml \ - --s3-bucket BUCKET_NAME -my-application$ sam deploy \ - --template-file packaged.yaml \ - --stack-name sam-app \ - --capabilities CAPABILITY_IAM -``` - -Open the [**Applications**](https://console.aws.amazon.com/lambda/home#/applications) page of the Lambda console, and choose your application. When the deployment completes, view the application resources on the **Overview** tab to see the new resource. Then, choose the function to see the updated configuration that specifies the dead-letter queue. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, the AWS SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs that are generated by your 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. - -**NOTE:** This command works for all Lambda functions, not just the ones you deploy using AWS SAM. - -```bash -my-application$ sam logs -n SNSPayloadLogger --stack-name sam-app --tail -``` - -**NOTE:** This uses the logical name of the function within the stack. This is the correct name to use when searching logs inside an AWS Lambda function within a CloudFormation stack, even if the deployed function name varies due to CloudFormation's unique resource name generation. - -You can find more information and examples about filtering Lambda function logs in the [AWS SAM CLI documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -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. - -```bash -my-application$ npm install -my-application$ npm run test -``` - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the [AWS SAM Developer Guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html). - -Next, you can use the AWS Serverless Application Repository to deploy ready-to-use apps that go beyond Hello World samples and learn how authors developed their applications. For more information, see the [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) and the [AWS Serverless Application Repository Developer Guide](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html). diff --git a/nodejs16.x/sns/{{cookiecutter.project_name}}/__tests__/unit/handlers/sns-payload-logger.test.js b/nodejs16.x/sns/{{cookiecutter.project_name}}/__tests__/unit/handlers/sns-payload-logger.test.js deleted file mode 100644 index eb7857957..000000000 --- a/nodejs16.x/sns/{{cookiecutter.project_name}}/__tests__/unit/handlers/sns-payload-logger.test.js +++ /dev/null @@ -1,23 +0,0 @@ -// Import all functions from sns-payload-logger.js -const snsPayloadLogger = require('../../../src/handlers/sns-payload-logger.js'); - -describe('Test for sns-payload-logger', function () { - // This test invokes the sns-payload-logger Lambda function and verifies that the received payload is logged - it('Verifies the payload is logged', async() => { - // Mock console.log statements so we can verify them. For more information, see - // https://jestjs.io/docs/en/mock-functions.html - console.info = jest.fn() - - // Create a sample payload with SNS message format - var payload = { - TopicArn: "arn:aws:sns:us-west-2:123456789012:SimpleTopic", - Message: "This is a notification from SNS", - Subject: "SNS Notification" - } - - await snsPayloadLogger.snsPayloadLoggerHandler(payload, null) - - // Verify that console.info has been called with the expected payload - expect(console.info).toHaveBeenCalledWith(payload) - }); -}); diff --git a/nodejs16.x/sns/{{cookiecutter.project_name}}/buildspec.yml b/nodejs16.x/sns/{{cookiecutter.project_name}}/buildspec.yml deleted file mode 100755 index 86e7a9ebf..000000000 --- a/nodejs16.x/sns/{{cookiecutter.project_name}}/buildspec.yml +++ /dev/null @@ -1,25 +0,0 @@ -version: 0.2 - -phases: - install: - commands: - # Install all dependencies (including dependencies for running tests) - - npm install - pre_build: - commands: - # Discover and run unit tests in the '__tests__' directory - - npm run test - # Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda - - rm -rf ./__tests__ - # Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json) - - npm prune --production - build: - commands: - # Use AWS SAM to package the application by using AWS CloudFormation - - aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --output-template template-export.yml -artifacts: - type: zip - files: - - template-export.yml - - diff --git a/nodejs16.x/sns/{{cookiecutter.project_name}}/events/event-sns.json b/nodejs16.x/sns/{{cookiecutter.project_name}}/events/event-sns.json deleted file mode 100644 index baa02e78b..000000000 --- a/nodejs16.x/sns/{{cookiecutter.project_name}}/events/event-sns.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "TopicArn": "arn:aws:sns:us-west-2:123456789012:SimpleTopic", - "Message": "This is a notification from SNS", - "Subject": "SNS Notification" -} \ No newline at end of file diff --git a/nodejs16.x/sns/{{cookiecutter.project_name}}/package.json b/nodejs16.x/sns/{{cookiecutter.project_name}}/package.json deleted file mode 100755 index 57ccc5af5..000000000 --- a/nodejs16.x/sns/{{cookiecutter.project_name}}/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "replaced-by-user-input", - "description": "replaced-by-user-input", - "version": "0.0.1", - "private": true, - "dependencies": {}, - "devDependencies": { - "jest": "^26.6.3" - }, - "scripts": { - "test": "jest" - } -} diff --git a/nodejs16.x/sns/{{cookiecutter.project_name}}/src/handlers/sns-payload-logger.js b/nodejs16.x/sns/{{cookiecutter.project_name}}/src/handlers/sns-payload-logger.js deleted file mode 100755 index 2abb76c5c..000000000 --- a/nodejs16.x/sns/{{cookiecutter.project_name}}/src/handlers/sns-payload-logger.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * A Lambda function that logs the payload received from SNS. - */ -exports.snsPayloadLoggerHandler = async (event, context) => { - // All log statements are written to CloudWatch by default. For more information, see - // https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-logging.html - console.info(event); -} diff --git a/nodejs16.x/sns/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/sns/{{cookiecutter.project_name}}/template.yaml deleted file mode 100755 index 0fefeca78..000000000 --- a/nodejs16.x/sns/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,48 +0,0 @@ -# This is the SAM template that represents the architecture of your serverless application -# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html - -# The AWSTemplateFormatVersion identifies the capabilities of the template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html -AWSTemplateFormatVersion: 2010-09-09 -Description: >- - {{cookiecutter.project_name}} - -# Transform section specifies one or more macros that AWS CloudFormation uses to process your template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html -Transform: -- AWS::Serverless-2016-10-31 - -# Resources declares the AWS resources that you want to include in the stack -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html -Resources: - # This is an SNS Topic with all default configuration properties. To learn more about the available options, see - # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-topic.html - SimpleTopic: - Type: AWS::SNS::Topic - - # This is the Lambda function definition associated with the source code: sns-payload-logger.js. For all available properties, see - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - SNSPayloadLogger: - Type: AWS::Serverless::Function - Properties: - Description: A Lambda function that logs the payload of messages sent to an associated SNS topic. - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Handler: src/handlers/sns-payload-logger.snsPayloadLoggerHandler - # This property associates this Lambda function with the SNS topic defined above, so that whenever the topic - # receives a message, the Lambda function is invoked - Events: - SNSTopicEvent: - Type: SNS - Properties: - Topic: !Ref SimpleTopic - MemorySize: 128 - Timeout: 100 - Policies: - # Give Lambda basic execution Permission to the helloFromLambda - - AWSLambdaBasicExecutionRole diff --git a/nodejs16.x/sqs/.gitignore b/nodejs16.x/sqs/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/sqs/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/sqs/README.md b/nodejs16.x/sqs/README.md deleted file mode 100644 index 0b0d19d93..000000000 --- a/nodejs16.x/sqs/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# {{cookiecutter.project_name}} - -A cookiecutter template to create a NodeJS SQS Quick Start Application using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x --app-template quick-start-sqs --name sqs-app` - -> **NOTE**: ``--name`` allows you to specify a different project folder name - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/sqs/cookiecutter.json b/nodejs16.x/sqs/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/sqs/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/sqs/setup.cfg b/nodejs16.x/sqs/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/sqs/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/sqs/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/sqs/{{cookiecutter.project_name}}/.gitignore deleted file mode 100755 index b512c09d4..000000000 --- a/nodejs16.x/sqs/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff --git a/nodejs16.x/sqs/{{cookiecutter.project_name}}/README.md b/nodejs16.x/sqs/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 55386ff1c..000000000 --- a/nodejs16.x/sqs/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,141 +0,0 @@ -# {{cookiecutter.project_name}} - -This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) command line interface (CLI). It includes the following files and folders: - -- `src` - Code for the application's Lambda function. -- `events` - Invocation events that you can use to invoke the function. -- `__tests__` - Unit tests for the application code. -- `template.yaml` - A template that defines the application's AWS resources. - -Resources for this project are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open-source plugin for popular IDEs that uses the AWS SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds step-through debugging for Lambda function code. - -To get started, see the following: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The AWS SAM CLI is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the AWS SAM CLI, you need the following tools: - -* AWS SAM CLI - [Install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html). -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the npm package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community). - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -## Use the AWS SAM CLI to build and test locally - -Build your application by using the `sam build` command. - -```bash -my-application$ sam build -``` - -The AWS SAM CLI installs dependencies that are defined in `package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -my-application$ sam local invoke SQSPayloadLogger --event events/event-sqs.json -``` - -## Add a resource to your application - -The application template uses 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 that aren't included in the [AWS SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use the standard [AWS CloudFormation resource types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html). - -Update `template.yaml` to add a dead-letter queue to your application. In the **Resources** section, add a resource named **MyQueue** with the type **AWS::SQS::Queue**. Then add a property to the **AWS::Serverless::Function** resource named **DeadLetterQueue** that targets the queue's Amazon Resource Name (ARN), and a policy that grants the function permission to access the queue. - -``` -Resources: - MyQueue: - Type: AWS::SQS::Queue - SQSPayloadLogger: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/sqs-payload-logger.sqsPayloadLoggerHandler - Runtime: nodejs16.x - DeadLetterQueue: - Type: SQS - TargetArn: !GetAtt MyQueue.Arn - Policies: - - SQSSendMessagePolicy: - QueueName: !GetAtt MyQueue.QueueName -``` - -The dead-letter queue is a location for Lambda to send events that could not be processed. It's only used if you invoke your function asynchronously, but it's useful here to show how you can modify your application's resources and function configuration. - -Deploy the updated application. - -```bash -my-application$ sam deploy -``` - -Open the [**Applications**](https://console.aws.amazon.com/lambda/home#/applications) page of the Lambda console, and choose your application. When the deployment completes, view the application resources on the **Overview** tab to see the new resource. Then, choose the function to see the updated configuration that specifies the dead-letter queue. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, the AWS SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs that are generated by your 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. - -**NOTE:** This command works for all Lambda functions, not just the ones you deploy using AWS SAM. - -```bash -my-application$ sam logs -n SQSPayloadLogger --stack-name sam-app --tail -``` - -**NOTE:** This uses the logical name of the function within the stack. This is the correct name to use when searching logs inside an AWS Lambda function within a CloudFormation stack, even if the deployed function name varies due to CloudFormation's unique resource name generation. - -You can find more information and examples about filtering Lambda function logs in the [AWS SAM CLI documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -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. - -```bash -my-application$ npm install -my-application$ npm run test -``` - -## Cleanup - -To delete the sample application and the bucket that you created, use the AWS CLI. - -```bash -my-application$ sam delete --stack-name sam-app -my-application$ aws s3 rb s3://BUCKET_NAME -``` - -## Resources - -For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the [AWS SAM Developer Guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html). - -Next, you can use the AWS Serverless Application Repository to deploy ready-to-use apps that go beyond Hello World samples and learn how authors developed their applications. For more information, see the [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) and the [AWS Serverless Application Repository Developer Guide](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html). diff --git a/nodejs16.x/sqs/{{cookiecutter.project_name}}/__tests__/unit/handlers/sqs-payload-logger.test.js b/nodejs16.x/sqs/{{cookiecutter.project_name}}/__tests__/unit/handlers/sqs-payload-logger.test.js deleted file mode 100644 index 9f77041e1..000000000 --- a/nodejs16.x/sqs/{{cookiecutter.project_name}}/__tests__/unit/handlers/sqs-payload-logger.test.js +++ /dev/null @@ -1,29 +0,0 @@ -// Import all functions from sqs-payload-logger.js -const sqsPayloadLogger = require('../../../src/handlers/sqs-payload-logger.js'); - -describe('Test for sqs-payload-logger', function () { - // This test invokes the sqs-payload-logger Lambda function and verifies that the received payload is logged - it('Verifies the payload is logged', async () => { - // Mock console.log statements so we can verify them. For more information, see - // https://jestjs.io/docs/en/mock-functions.html - console.info = jest.fn() - - // Create a sample payload with SQS message format - var payload = { - DelaySeconds: 10, - MessageAttributes: { - "Sender": { - DataType: "String", - StringValue: "sqs-payload-logger" - } - }, - MessageBody: "This message was sent by the sqs-payload-logger Lambda function", - QueueUrl: "SQS_QUEUE_URL" - } - - await sqsPayloadLogger.sqsPayloadLoggerHandler(payload, null) - - // Verify that console.info has been called with the expected payload - expect(console.info).toHaveBeenCalledWith(JSON.stringify(payload)) - }); -}); diff --git a/nodejs16.x/sqs/{{cookiecutter.project_name}}/buildspec.yml b/nodejs16.x/sqs/{{cookiecutter.project_name}}/buildspec.yml deleted file mode 100755 index adb0a1019..000000000 --- a/nodejs16.x/sqs/{{cookiecutter.project_name}}/buildspec.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 0.2 - -phases: - install: - commands: - # Install all dependencies (including dependencies for running tests) - - npm install - pre_build: - commands: - # Discover and run unit tests in the '__tests__' directory - - npm run test - # Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda - - rm -rf ./__tests__ - # Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json) - - npm prune --production - build: - commands: - # Use AWS SAM to package the application by using AWS CloudFormation - - aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --output-template template-export.yml -artifacts: - type: zip - files: - - template-export.yml diff --git a/nodejs16.x/sqs/{{cookiecutter.project_name}}/events/event-sqs.json b/nodejs16.x/sqs/{{cookiecutter.project_name}}/events/event-sqs.json deleted file mode 100644 index f691c8780..000000000 --- a/nodejs16.x/sqs/{{cookiecutter.project_name}}/events/event-sqs.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "DelaySeconds": 10, - "MessageAttributes": { - "Sender": { - "DataType": "String", - "StringValue": "sqs-payload-logger" - } - }, - "MessageBody": "This message was sent by the sqs-payload-logger Lambda function", - "QueueUrl": "SQS_QUEUE_URL" -} diff --git a/nodejs16.x/sqs/{{cookiecutter.project_name}}/package.json b/nodejs16.x/sqs/{{cookiecutter.project_name}}/package.json deleted file mode 100755 index 57ccc5af5..000000000 --- a/nodejs16.x/sqs/{{cookiecutter.project_name}}/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "replaced-by-user-input", - "description": "replaced-by-user-input", - "version": "0.0.1", - "private": true, - "dependencies": {}, - "devDependencies": { - "jest": "^26.6.3" - }, - "scripts": { - "test": "jest" - } -} diff --git a/nodejs16.x/sqs/{{cookiecutter.project_name}}/src/handlers/sqs-payload-logger.js b/nodejs16.x/sqs/{{cookiecutter.project_name}}/src/handlers/sqs-payload-logger.js deleted file mode 100755 index 99d0cf83e..000000000 --- a/nodejs16.x/sqs/{{cookiecutter.project_name}}/src/handlers/sqs-payload-logger.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * A Lambda function that logs the payload received from SQS. - */ -exports.sqsPayloadLoggerHandler = async (event, context) => { - // All log statements are written to CloudWatch by default. For more information, see - // https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-logging.html - console.info(JSON.stringify(event)); -} diff --git a/nodejs16.x/sqs/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/sqs/{{cookiecutter.project_name}}/template.yaml deleted file mode 100755 index a569cdd6b..000000000 --- a/nodejs16.x/sqs/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,48 +0,0 @@ -# This is the SAM template that represents the architecture of your serverless application -# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html - -# The AWSTemplateFormatVersion identifies the capabilities of the template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html -AWSTemplateFormatVersion: 2010-09-09 -Description: >- - {{cookiecutter.project_name}} - -# Transform section specifies one or more macros that AWS CloudFormation uses to process your template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html -Transform: -- AWS::Serverless-2016-10-31 - -# Resources declares the AWS resources that you want to include in the stack -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html -Resources: - # This is an SQS queue with all default configuration properties. To learn more about the available options, see - # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html - SimpleQueue: - Type: AWS::SQS::Queue - - # This is the Lambda function definition associated with the source code: sqs-payload-logger.js. For all available properties, see - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - SQSPayloadLogger: - Type: AWS::Serverless::Function - Properties: - Description: A Lambda function that logs the payload of messages sent to an associated SQS queue. - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Handler: src/handlers/sqs-payload-logger.sqsPayloadLoggerHandler - # This property associates this Lambda function with the SQS queue defined above, so that whenever the queue - # receives a message, the Lambda function is invoked - Events: - SQSQueueEvent: - Type: SQS - Properties: - Queue: !GetAtt SimpleQueue.Arn - MemorySize: 128 - Timeout: 25 # Chosen to be less than the default SQS Visibility Timeout of 30 seconds - Policies: - # Give Lambda basic execution Permission to the helloFromLambda - - AWSLambdaBasicExecutionRole diff --git a/nodejs16.x/step-func-conn/.gitignore b/nodejs16.x/step-func-conn/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/step-func-conn/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/step-func-conn/README.md b/nodejs16.x/step-func-conn/README.md deleted file mode 100644 index 824c67925..000000000 --- a/nodejs16.x/step-func-conn/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Cookiecutter NodeJS Step Functions Sample App (Stock Trader) for SAM based Serverless App - -A cookiecutter template to create a NodeJS Step Functions Sample App (Stock Trader) boilerplate using -[Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -This application creates a mock stock trading workflow which runs on a pre-defined schedule. It demonstrates the power of Step Functions to orchestrate Lambda functions and other AWS resources to form complex and robust workflows, coupled with event-driven development using Amazon EventBridge. - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x --app-template step-functions-with-connectors--name multi-step-app` - -> **NOTE**: ``--name`` allows you to specify a different project folder name (`sam-app` is the default) - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/step-func-conn/cookiecutter.json b/nodejs16.x/step-func-conn/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/step-func-conn/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/step-func-conn/setup.cfg b/nodejs16.x/step-func-conn/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/step-func-conn/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 5854f05ec..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1,207 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test -.env*.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Storybook build outputs -.out -.storybook-out -storybook-static - -# rollup.js default build output -dist/ - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# Temporary folders -tmp/ -temp/ - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/README.md b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index fd464f374..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,137 +0,0 @@ -# {{ cookiecutter.project_name }} - -This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders: - -- functions - Code for the application's Lambda functions to check the value of, buy, or sell shares of a stock. -- statemachines - Definition for the state machine that orchestrates the stock trading workflow. -- template.yaml - A template that defines the application's AWS resources. - -This application creates a mock stock trading workflow which runs on a pre-defined schedule (note that the schedule is disabled by default to avoid incurring charges). It demonstrates the power of Step Functions to orchestrate Lambda functions and other AWS resources to form complex and robust workflows, coupled with event-driven development using Amazon EventBridge. - -AWS Step Functions lets you coordinate multiple AWS services into serverless workflows so you can build and update apps quickly. Using Step Functions, you can design and run workflows that stitch together services, such as AWS Lambda, AWS Fargate, and Amazon SageMaker, into feature-rich applications. - -The application uses several AWS resources, including Step Functions state machines, Lambda functions and an EventBridge rule trigger. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test the Lambda functions within your application, you can use the AWS Toolkit. The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -The AWS Toolkit for VS Code includes full support for state machine visualization, enabling you to visualize your state machine in real time as you build. The AWS Toolkit for VS Code includes a language server for Amazon States Language, which lints your state machine definition to highlight common errors, provides auto-complete support, and code snippets for each state, enabling you to build state machines faster. - -## Deploy the sample application - -The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. - -To use the SAM CLI, you need the following tools: - -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the NPM package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -You can find your State Machine ARN in the output values displayed after deployment. - -## Use the SAM CLI to build and test locally - -Build the Lambda functions in your application with the `sam build --use-container` command. - -```bash -{{ cookiecutter.project_name }}$ sam build -``` - -The SAM CLI installs dependencies defined in `functions/*/package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -## Add a resource to your application -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. - -## Fetch, tail, and filter Lambda function logs - -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. - -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. - -```bash -{{ cookiecutter.project_name }}$ sam logs -n StockCheckerFunction --stack-name {{ cookiecutter.project_name }} --tail -``` - -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). - -## Unit tests - -Tests are defined in the `functions/*/tests` folder in this project. Use NPM to install the [Mocha test framework](https://mochajs.org/) and run unit tests. - -```bash -{{ cookiecutter.project_name }}$ cd functions/stock-checker -stock-checker$ npm install -stock-checker$ npm run test -``` - -## Testing Step Functions locally -Developers can test their state machines locally using Step Functions Local before deploying them to an AWS account. Often, developers want to test the control and data flows of their state machine executions in isolation, without any dependency on service integration availability. This is now possible using the [Mocked Service Integrations for Step Functions Local](https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-test-sm-exec.html). - -The `statemachine/tests/MockConfigFile.json` contains various test cases with mocked service integrations. - -- `HappyPathSellStockTest` - This test mocks the output of Check Stock Value, Sell Stock and Record Transaction using LambdaMockedSuccessValueGreaterThan50, SellStockLambdaMockedResponse and RecordTransactionDDBMockedResponse respectively. -- `HappyPathBuyStockTest` - This test mocks the output of Check Stock Value, Buy Stock and Record Transaction using LambdaMockedSuccessValueLowerThan50, BuyStockLambdaMockedResponse and RecordTransactionDDBMockedResponse respectively. -- `CheckStockRetryOnServiceExceptionTest` and `SellStockRetryOnServiceExceptionTest`- These tests mocks the failure with exponential retries. - -This application also provides a `makefile` which has all the required commands to run docker [`make run`], create state machine and execute tests [`make all`], and checking history [`make history`]. - -On a terminal window, first start with running docker: - -```bash -make run -``` - -On a different terminal window/tab, you can then run: - -```bash -make all -``` - -Finally, you can check history of each execution by running: - -```bash -make history -``` - -Check [`makefile`](./makefile) for details - - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -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. - -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/) diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/.npmignore b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/app.js b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/app.js deleted file mode 100644 index 2168da955..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/app.js +++ /dev/null @@ -1,30 +0,0 @@ -const crypto = require("crypto"); - -function getRandomInt(max) { - return Math.floor(Math.random() * Math.floor(max)) + 1; -} - -/** - * Sample Lambda function which mocks the operation of buying a random number of shares for a stock. - * For demonstration purposes, this Lambda function does not actually perform any actual transactions. It simply returns a mocked result. - * - * @param {Object} event - Input event to the Lambda function - * @param {Object} context - Lambda Context runtime methods and attributes - * - * @returns {Object} object - Object containing details of the stock buying transaction - * - */ -exports.lambdaHandler = async (event, context) => { - // Get the price of the stock provided as input - stock_price = event["stock_price"] - var date = new Date(); - // Mocked result of a stock buying transaction - let transaction_result = { - 'id': crypto.randomBytes(16).toString("hex"), // Unique ID for the transaction - 'price': stock_price.toString(), // Price of each share - 'type': "buy", // Type of transaction(buy/ sell) - 'qty': getRandomInt(10).toString(), // Number of shares bought / sold(We are mocking this as a random integer between 1 and 10) - 'timestamp': date.toISOString(), // Timestamp of the when the transaction was completed - } - return transaction_result -}; diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/package.json b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/package.json deleted file mode 100644 index 056a8d808..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "stock_checker", - "version": "1.0.0", - "description": "Mock stock checker for NodeJS", - "main": "app.js", - "repository": "TODO", - "author": "SAM CLI", - "license": "MIT", - "dependencies": {}, - "scripts": { - "test": "mocha tests/unit/" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^9.1.4" - } -} diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/tests/unit/test-handler.js b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/tests/unit/test-handler.js deleted file mode 100644 index 85dcb423b..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-buyer/tests/unit/test-handler.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -const app = require('../../app.js'); -const chai = require('chai'); -const expect = chai.expect; -var event, context; - -describe('Tests Stock Buyer', function () { - it('Verifies response', async () => { - event = { - 'stock_price': 25 - } - const result = await app.lambdaHandler(event, context) - - expect(result).to.be.an('object'); - expect(result).to.have.all.keys('id', 'price', 'type', 'timestamp', 'qty'); - expect(result.type).to.equal('buy'); - let qty = parseInt(result.qty); - expect(qty).to.be.at.least(1); - expect(qty).to.be.at.most(10); - }); -}); diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/.npmignore b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/app.js b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/app.js deleted file mode 100644 index 99a9b64d2..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/app.js +++ /dev/null @@ -1,19 +0,0 @@ -function getRandomInt(max) { - return Math.floor(Math.random() * Math.floor(max)); -} - -/** - * Sample Lambda function which mocks the operation of checking the current price of a stock. - * For demonstration purposes this Lambda function simply returns a random integer between 0 and 100 as the stock price. - * - * @param {Object} event - Input event to the Lambda function - * @param {Object} context - Lambda Context runtime methods and attributes - * - * @returns {Object} object - Object containing the current price of the stock - * - */ -exports.lambdaHandler = async (event, context) => { - // Check current price of the stock - stock_price = getRandomInt(100) // Current stock price is mocked as a random integer between 0 and 100 - return { 'stock_price': stock_price } -}; diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/package.json b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/package.json deleted file mode 100644 index 056a8d808..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "stock_checker", - "version": "1.0.0", - "description": "Mock stock checker for NodeJS", - "main": "app.js", - "repository": "TODO", - "author": "SAM CLI", - "license": "MIT", - "dependencies": {}, - "scripts": { - "test": "mocha tests/unit/" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^9.1.4" - } -} diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/tests/unit/test-handler.js b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/tests/unit/test-handler.js deleted file mode 100644 index 72bbd7aa9..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-checker/tests/unit/test-handler.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -const app = require('../../app.js'); -const chai = require('chai'); -const expect = chai.expect; -var event, context; - -describe('Tests Stock Checker', function () { - it('Verifies response', async () => { - const result = await app.lambdaHandler(event, context) - - expect(result).to.be.an('object'); - expect(result.stock_price).to.be.an('number'); - expect(result.stock_price).to.be.at.least(0); - expect(result.stock_price).to.be.at.most(100); - }); -}); diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/.npmignore b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/app.js b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/app.js deleted file mode 100644 index c165a2852..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/app.js +++ /dev/null @@ -1,30 +0,0 @@ -const crypto = require("crypto"); - -function getRandomInt(max) { - return Math.floor(Math.random() * Math.floor(max)) + 1; -} - -/** - * Sample Lambda function which mocks the operation of selling a random number of shares for a stock. - * For demonstration purposes, this Lambda function does not actually perform any actual transactions. It simply returns a mocked result. - * - * @param {Object} event - Input event to the Lambda function - * @param {Object} context - Lambda Context runtime methods and attributes - * - * @returns {Object} object - Object containing details of the stock selling transaction - * - */ -exports.lambdaHandler = async (event, context) => { - // Get the price of the stock provided as input - stock_price = event["stock_price"] - var date = new Date(); - // Mocked result of a stock selling transaction - let transaction_result = { - 'id': crypto.randomBytes(16).toString("hex"), // Unique ID for the transaction - 'price': stock_price.toString(), // Price of each share - 'type': "sell", // Type of transaction(buy/ sell) - 'qty': getRandomInt(10).toString(), // Number of shares bought / sold(We are mocking this as a random integer between 1 and 10) - 'timestamp': date.toISOString(), // Timestamp of the when the transaction was completed - } - return transaction_result -}; diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/package.json b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/package.json deleted file mode 100644 index 056a8d808..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "stock_checker", - "version": "1.0.0", - "description": "Mock stock checker for NodeJS", - "main": "app.js", - "repository": "TODO", - "author": "SAM CLI", - "license": "MIT", - "dependencies": {}, - "scripts": { - "test": "mocha tests/unit/" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^9.1.4" - } -} diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/tests/unit/test-handler.js b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/tests/unit/test-handler.js deleted file mode 100644 index f242250b1..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/functions/stock-seller/tests/unit/test-handler.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -const app = require('../../app.js'); -const chai = require('chai'); -const expect = chai.expect; -var event, context; - -describe('Tests Stock Seller', function () { - it('Verifies response', async () => { - event = { - 'stock_price': 75 - } - const result = await app.lambdaHandler(event, context) - - expect(result).to.be.an('object'); - expect(result).to.have.all.keys('id', 'price', 'type', 'timestamp', 'qty'); - expect(result.type).to.equal('sell'); - let qty = parseInt(result.qty); - expect(qty).to.be.at.least(1); - expect(qty).to.be.at.most(10); - }); -}); diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/makefile b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/makefile deleted file mode 100644 index 3e9440fd3..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/makefile +++ /dev/null @@ -1,71 +0,0 @@ -ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) - -run: - docker run -p 8083:8083 \ - --mount type=bind,readonly,source=$(ROOT_DIR)/statemachine/test/MockConfigFile.json,destination=/home/StepFunctionsLocal/MockConfigFile.json \ - -e SFN_MOCK_CONFIG="/home/StepFunctionsLocal/MockConfigFile.json" \ - amazon/aws-stepfunctions-local - -create: - sed -E -e 's/\$$\{.+\}/arn:aws:lambda:us-east-1:123456789012:function:mock/' statemachine/stock_trader.asl.json > statemachine/test/mocked.test.asl.json - aws stepfunctions create-state-machine \ - --endpoint-url http://localhost:8083 \ - --definition file://statemachine/test/mocked.test.asl.json \ - --name "StockTradingLocalTesting" \ - --role-arn "arn:aws:iam::123456789012:role/DummyRole" \ - --no-cli-pager - rm statemachine/test/mocked.test.asl.json - -happypathsellstocktest: - aws stepfunctions start-execution \ - --endpoint http://localhost:8083 \ - --name HappyPathSellStockTest \ - --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:StockTradingLocalTesting#HappyPathSellStockTest \ - --no-cli-pager - -happypathbuystocktest: - aws stepfunctions start-execution \ - --endpoint http://localhost:8083 \ - --name HappyPathBuyStockTest \ - --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:StockTradingLocalTesting#HappyPathBuyStockTest \ - --no-cli-pager - -checkstockerrorwithretry: - aws stepfunctions start-execution \ - --endpoint http://localhost:8083 \ - --name checkStockErrorExecution \ - --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:StockTradingLocalTesting#CheckStockRetryOnServiceExceptionTest \ - --no-cli-pager - -sellstockerrorwithretry: - aws stepfunctions start-execution \ - --endpoint http://localhost:8083 \ - --name sellStockErrorExecution \ - --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:StockTradingLocalTesting#SellStockRetryOnServiceExceptionTest \ - --no-cli-pager - - -all: create happypathsellstocktest happypathbuystocktest checkstockerrorwithretry sellstockerrorwithretry - -happypathsellstocktest-h: - aws stepfunctions get-execution-history \ - --endpoint http://localhost:8083 \ - --execution-arn arn:aws:states:us-east-1:123456789012:execution:StockTradingLocalTesting:HappyPathSellStockTest \ - --query 'events[?type==`TaskStateExited` && stateExitedEventDetails.name==`Record Transaction`]' \ - --no-cli-pager - -checkstockerror: - aws stepfunctions get-execution-history \ - --endpoint http://localhost:8083 \ - --execution-arn arn:aws:states:us-east-1:123456789012:execution:StockTradingLocalTesting:checkStockErrorExecution \ - --query 'events[?type==`TaskStateExited` && stateExitedEventDetails.name==`Record Transaction` ]' \ - --no-cli-pager - -sellstockerror: - aws stepfunctions get-execution-history \ - --endpoint http://localhost:8083 \ - --execution-arn arn:aws:states:us-east-1:123456789012:execution:StockTradingLocalTesting:sellStockErrorExecution \ - --query 'events[?type==`TaskStateExited` && stateExitedEventDetails.name==`Record Transaction` ]' \ - --no-cli-pager - -history: happypathsellstocktest-h checkstockerror sellstockerror \ No newline at end of file diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/statemachine/stock_trader.asl.json b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/statemachine/stock_trader.asl.json deleted file mode 100644 index c29281b34..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/statemachine/stock_trader.asl.json +++ /dev/null @@ -1,97 +0,0 @@ -{ - "Comment": "A state machine that does mock stock trading.", - "StartAt": "Check Stock Value", - "States": { - "Check Stock Value": { - "Type": "Task", - "Resource": "${StockCheckerFunctionArn}", - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 15, - "MaxAttempts": 5, - "BackoffRate": 1.5 - } - ], - "Next": "Buy or Sell?" - }, - "Buy or Sell?": { - "Type": "Choice", - "Choices": [ - { - "Variable": "$.stock_price", - "NumericLessThanEquals": 50, - "Next": "Buy Stock" - } - ], - "Default": "Sell Stock" - }, - "Sell Stock": { - "Type": "Task", - "Resource": "${StockSellerFunctionArn}", - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 2, - "MaxAttempts": 3, - "BackoffRate": 1 - } - ], - "Next": "Record Transaction" - }, - "Buy Stock": { - "Type": "Task", - "Resource": "${StockBuyerFunctionArn}", - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 2, - "MaxAttempts": 3, - "BackoffRate": 1 - } - ], - "Next": "Record Transaction" - }, - "Record Transaction": { - "Type": "Task", - "Resource": "${DDBPutItem}", - "Parameters": { - "TableName": "${DDBTable}", - "Item": { - "Id": { - "S.$": "$.id" - }, - "Type": { - "S.$": "$.type" - }, - "Price": { - "N.$": "$.price" - }, - "Quantity": { - "N.$": "$.qty" - }, - "Timestamp": { - "S.$": "$.timestamp" - } - } - }, - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 20, - "MaxAttempts": 5, - "BackoffRate": 10 - } - ], - "End": true - } - } -} \ No newline at end of file diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/statemachine/test/MockConfigFile.json b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/statemachine/test/MockConfigFile.json deleted file mode 100644 index 20db6d24c..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/statemachine/test/MockConfigFile.json +++ /dev/null @@ -1,142 +0,0 @@ -{ - "StateMachines": { - "StockTradingLocalTesting": { - "TestCases": { - "HappyPathSellStockTest": { - "Check Stock Value": "LambdaMockedSuccessValueGreaterThan50", - "Sell Stock": "SellStockLambdaMockedResponse", - "Record Transaction": "RecordTransactionDDBMockedResponse" - }, - "HappyPathBuyStockTest": { - "Check Stock Value": "LambdaMockedSuccessValueLowerThan50", - "Buy Stock": "BuyStockLambdaMockedResponse", - "Record Transaction": "RecordTransactionDDBMockedResponse" - }, - "CheckStockRetryOnServiceExceptionTest": { - "Check Stock Value": "CheckStockLambdaMockedRetryWithSuccess", - "Sell Stock": "SellStockLambdaMockedResponse", - "Record Transaction": "RecordTransactionDDBMockedResponse" - }, - "SellStockRetryOnServiceExceptionTest": { - "Check Stock Value": "LambdaMockedSuccessValueGreaterThan50", - "Sell Stock": "SellStockLambdaMockedRetryWithSuccess", - "Record Transaction": "RecordTransactionDDBMockedResponse" - } - } - } - }, - "MockedResponses": { - "LambdaMockedSuccessValueGreaterThan50": { - "0": { - "Return": { - "stock_price": 98 - } - } - }, - "LambdaMockedSuccessValueLowerThan50": { - "0": { - "Return": { - "stock_price": 32 - } - } - }, - "SellStockLambdaMockedResponse": { - "0": { - "Return": { - "id": "8cd8e4d92fe716b7cedff5636ab9d24e", - "price": "98", - "type": "sell", - "qty": "7", - "timestamp": "2022-06-22T21:14:18.228Z" - } - } - }, - "BuyStockLambdaMockedResponse": { - "0": { - "Return": { - "id": "8cd8e4d92fe716b7cedff5636ab9d24e", - "price": "32", - "type": "buy", - "qty": "7", - "timestamp": "2022-06-22T21:14:18.228Z" - } - } - }, - "RecordTransactionDDBMockedResponse": { - "0": { - "Return": { - "resourceType": "dynamodb", - "resource": "putItem", - "output": { - "SdkHttpMetadata": { - "AllHttpHeaders": { - "Server": [ - "Server" - ], - "Connection": [ - "keep-alive" - ], - "x-amzn-RequestId": [ - "LAT641GUVNBRI0DC1HC6S4MDH3VV4KQNSO5AEMVJF66Q9ASUAAJG" - ], - "x-amz-crc32": [ - "2745614147" - ], - "Content-Length": [ - "2" - ], - "Date": [ - "Wed, 22 Jun 2022 21:14:18 GMT" - ], - "Content-Type": [ - "application/x-amz-json-1.0" - ] - }, - "HttpHeaders": { - "Connection": "keep-alive", - "Content-Length": "2", - "Content-Type": "application/x-amz-json-1.0", - "Date": "Wed, 22 Jun 2022 21:14:18 GMT", - "Server": "Server", - "x-amz-crc32": "2745614147", - "x-amzn-RequestId": "LAT641GUVNBRI0DC1HC6S4MDH3VV4KQNSO5AEMVJF66Q9ASUAAJG" - }, - "HttpStatusCode": 200 - }, - "SdkResponseMetadata": { - "RequestId": "LAT641GUVNBRI0DC1HC6S4MDH3VV4KQNSO5AEMVJF66Q9ASUAAJG" - } - } - } - } - }, - "CheckStockLambdaMockedRetryWithSuccess": { - "0-2": { - "Throw": { - "Error": "States.TaskFailed" - } - }, - "3": { - "Return": { - "stock_price": 89 - } - } - }, - "SellStockLambdaMockedRetryWithSuccess": { - "0-2": { - "Throw": { - "Error": "States.TaskFailed" - } - }, - "3": { - "Return": { - "id": "8cd8e4d92fe716b7cedff5636ab9d24e", - "price": "98", - "type": "sell", - "qty": "5", - "timestamp": "2022-06-22T21:14:18.228Z" - } - } - } - } -} \ No newline at end of file diff --git a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index e8032106a..000000000 --- a/nodejs16.x/step-func-conn/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,109 +0,0 @@ -AWSTemplateFormatVersion: "2010-09-09" -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - - Sample SAM Template for {{ cookiecutter.project_name }} - -Resources: - SfnToStockCheckerFunctionConnector: - Type: AWS::Serverless::Connector # More info about Connector Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-connector.html - Properties: - Source: - Id: StockTradingStateMachine - Destination: - Id: StockCheckerFunction - Permissions: - - Write - - SfnToStockBuyerFunctionConnector: - Type: AWS::Serverless::Connector - Properties: - Source: - Id: StockTradingStateMachine - Destination: - Id: StockBuyerFunction - Permissions: - - Write - - SfnToStockSellerFunctionConnector: - Type: AWS::Serverless::Connector - Properties: - Source: - Id: StockTradingStateMachine - Destination: - Id: StockSellerFunction - Permissions: - - Write - - SfnToTransactionTableConnector: - Type: AWS::Serverless::Connector - Properties: - Source: - Id: StockTradingStateMachine - Destination: - Id: TransactionTable - Permissions: - - Write - - StockTradingStateMachine: - Type: AWS::Serverless::StateMachine # More info about State Machine Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html - Properties: - DefinitionUri: statemachine/stock_trader.asl.json - DefinitionSubstitutions: - StockCheckerFunctionArn: !GetAtt StockCheckerFunction.Arn - StockSellerFunctionArn: !GetAtt StockSellerFunction.Arn - StockBuyerFunctionArn: !GetAtt StockBuyerFunction.Arn - DDBPutItem: !Sub arn:${AWS::Partition}:states:::dynamodb:putItem - DDBTable: !Ref TransactionTable - Events: - HourlyTradingSchedule: - Type: Schedule # More info about Schedule Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-schedule.html - Properties: - Description: Schedule to run the stock trading state machine every hour - Enabled: False # This schedule is disabled by default to avoid incurring charges. - Schedule: "rate(1 hour)" - Policies: - - CloudWatchPutMetricPolicy: {} - - StockCheckerFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html - Properties: - CodeUri: functions/stock-checker/ - Handler: app.lambdaHandler - Runtime: nodejs16.x - - StockSellerFunction: - Type: AWS::Serverless::Function - Properties: - CodeUri: functions/stock-seller/ - Handler: app.lambdaHandler - Runtime: nodejs16.x - - StockBuyerFunction: - Type: AWS::Serverless::Function - Properties: - CodeUri: functions/stock-buyer/ - Handler: app.lambdaHandler - Runtime: nodejs16.x - - TransactionTable: - Type: AWS::Serverless::SimpleTable # More info about SimpleTable Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-simpletable.html - Properties: - PrimaryKey: - Name: Id - Type: String - ProvisionedThroughput: - ReadCapacityUnits: 1 - WriteCapacityUnits: 1 - -Outputs: - # StockTradingStateMachineHourlyTradingSchedule is an implicit Schedule event rule created out of Events key under Serverless::StateMachine - # Find out more about other implicit resources you can reference within SAM - # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html - StockTradingStateMachineArn: - Description: "Stock Trading state machine ARN" - Value: !Ref StockTradingStateMachine - StockTradingStateMachineRole: - Description: "IAM Role created for Stock Trading state machine based on the specified SAM Policy Templates" - Value: !GetAtt StockTradingStateMachineRole.Arn diff --git a/nodejs16.x/step-func/.gitignore b/nodejs16.x/step-func/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/step-func/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/step-func/README.md b/nodejs16.x/step-func/README.md deleted file mode 100644 index f26794507..000000000 --- a/nodejs16.x/step-func/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Cookiecutter NodeJS Step Functions Sample App (Stock Trader) for SAM based Serverless App - -A cookiecutter template to create a NodeJS Step Functions Sample App (Stock Trader) boilerplate using -[Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -This application creates a mock stock trading workflow which runs on a pre-defined schedule. It demonstrates the power of Step Functions to orchestrate Lambda functions and other AWS resources to form complex and robust workflows, coupled with event-driven development using Amazon EventBridge. - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x` - -> **NOTE**: ``--name`` allows you to specify a different project folder name (`sam-app` is the default) - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/step-func/cookiecutter.json b/nodejs16.x/step-func/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/step-func/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/step-func/setup.cfg b/nodejs16.x/step-func/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/step-func/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/step-func/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 5854f05ec..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1,207 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test -.env*.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Storybook build outputs -.out -.storybook-out -storybook-static - -# rollup.js default build output -dist/ - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# Temporary folders -tmp/ -temp/ - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/README.md b/nodejs16.x/step-func/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index fd464f374..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,137 +0,0 @@ -# {{ cookiecutter.project_name }} - -This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders: - -- functions - Code for the application's Lambda functions to check the value of, buy, or sell shares of a stock. -- statemachines - Definition for the state machine that orchestrates the stock trading workflow. -- template.yaml - A template that defines the application's AWS resources. - -This application creates a mock stock trading workflow which runs on a pre-defined schedule (note that the schedule is disabled by default to avoid incurring charges). It demonstrates the power of Step Functions to orchestrate Lambda functions and other AWS resources to form complex and robust workflows, coupled with event-driven development using Amazon EventBridge. - -AWS Step Functions lets you coordinate multiple AWS services into serverless workflows so you can build and update apps quickly. Using Step Functions, you can design and run workflows that stitch together services, such as AWS Lambda, AWS Fargate, and Amazon SageMaker, into feature-rich applications. - -The application uses several AWS resources, including Step Functions state machines, Lambda functions and an EventBridge rule trigger. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test the Lambda functions within your application, you can use the AWS Toolkit. The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -The AWS Toolkit for VS Code includes full support for state machine visualization, enabling you to visualize your state machine in real time as you build. The AWS Toolkit for VS Code includes a language server for Amazon States Language, which lints your state machine definition to highlight common errors, provides auto-complete support, and code snippets for each state, enabling you to build state machines faster. - -## Deploy the sample application - -The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. - -To use the SAM CLI, you need the following tools: - -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the NPM package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -You can find your State Machine ARN in the output values displayed after deployment. - -## Use the SAM CLI to build and test locally - -Build the Lambda functions in your application with the `sam build --use-container` command. - -```bash -{{ cookiecutter.project_name }}$ sam build -``` - -The SAM CLI installs dependencies defined in `functions/*/package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -## Add a resource to your application -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. - -## Fetch, tail, and filter Lambda function logs - -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. - -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. - -```bash -{{ cookiecutter.project_name }}$ sam logs -n StockCheckerFunction --stack-name {{ cookiecutter.project_name }} --tail -``` - -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). - -## Unit tests - -Tests are defined in the `functions/*/tests` folder in this project. Use NPM to install the [Mocha test framework](https://mochajs.org/) and run unit tests. - -```bash -{{ cookiecutter.project_name }}$ cd functions/stock-checker -stock-checker$ npm install -stock-checker$ npm run test -``` - -## Testing Step Functions locally -Developers can test their state machines locally using Step Functions Local before deploying them to an AWS account. Often, developers want to test the control and data flows of their state machine executions in isolation, without any dependency on service integration availability. This is now possible using the [Mocked Service Integrations for Step Functions Local](https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-test-sm-exec.html). - -The `statemachine/tests/MockConfigFile.json` contains various test cases with mocked service integrations. - -- `HappyPathSellStockTest` - This test mocks the output of Check Stock Value, Sell Stock and Record Transaction using LambdaMockedSuccessValueGreaterThan50, SellStockLambdaMockedResponse and RecordTransactionDDBMockedResponse respectively. -- `HappyPathBuyStockTest` - This test mocks the output of Check Stock Value, Buy Stock and Record Transaction using LambdaMockedSuccessValueLowerThan50, BuyStockLambdaMockedResponse and RecordTransactionDDBMockedResponse respectively. -- `CheckStockRetryOnServiceExceptionTest` and `SellStockRetryOnServiceExceptionTest`- These tests mocks the failure with exponential retries. - -This application also provides a `makefile` which has all the required commands to run docker [`make run`], create state machine and execute tests [`make all`], and checking history [`make history`]. - -On a terminal window, first start with running docker: - -```bash -make run -``` - -On a different terminal window/tab, you can then run: - -```bash -make all -``` - -Finally, you can check history of each execution by running: - -```bash -make history -``` - -Check [`makefile`](./makefile) for details - - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -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. - -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/) diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/.npmignore b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/app.js b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/app.js deleted file mode 100644 index 2168da955..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/app.js +++ /dev/null @@ -1,30 +0,0 @@ -const crypto = require("crypto"); - -function getRandomInt(max) { - return Math.floor(Math.random() * Math.floor(max)) + 1; -} - -/** - * Sample Lambda function which mocks the operation of buying a random number of shares for a stock. - * For demonstration purposes, this Lambda function does not actually perform any actual transactions. It simply returns a mocked result. - * - * @param {Object} event - Input event to the Lambda function - * @param {Object} context - Lambda Context runtime methods and attributes - * - * @returns {Object} object - Object containing details of the stock buying transaction - * - */ -exports.lambdaHandler = async (event, context) => { - // Get the price of the stock provided as input - stock_price = event["stock_price"] - var date = new Date(); - // Mocked result of a stock buying transaction - let transaction_result = { - 'id': crypto.randomBytes(16).toString("hex"), // Unique ID for the transaction - 'price': stock_price.toString(), // Price of each share - 'type': "buy", // Type of transaction(buy/ sell) - 'qty': getRandomInt(10).toString(), // Number of shares bought / sold(We are mocking this as a random integer between 1 and 10) - 'timestamp': date.toISOString(), // Timestamp of the when the transaction was completed - } - return transaction_result -}; diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/package.json b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/package.json deleted file mode 100644 index 056a8d808..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "stock_checker", - "version": "1.0.0", - "description": "Mock stock checker for NodeJS", - "main": "app.js", - "repository": "TODO", - "author": "SAM CLI", - "license": "MIT", - "dependencies": {}, - "scripts": { - "test": "mocha tests/unit/" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^9.1.4" - } -} diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/tests/unit/test-handler.js b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/tests/unit/test-handler.js deleted file mode 100644 index 85dcb423b..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-buyer/tests/unit/test-handler.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -const app = require('../../app.js'); -const chai = require('chai'); -const expect = chai.expect; -var event, context; - -describe('Tests Stock Buyer', function () { - it('Verifies response', async () => { - event = { - 'stock_price': 25 - } - const result = await app.lambdaHandler(event, context) - - expect(result).to.be.an('object'); - expect(result).to.have.all.keys('id', 'price', 'type', 'timestamp', 'qty'); - expect(result.type).to.equal('buy'); - let qty = parseInt(result.qty); - expect(qty).to.be.at.least(1); - expect(qty).to.be.at.most(10); - }); -}); diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/.npmignore b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/app.js b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/app.js deleted file mode 100644 index 99a9b64d2..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/app.js +++ /dev/null @@ -1,19 +0,0 @@ -function getRandomInt(max) { - return Math.floor(Math.random() * Math.floor(max)); -} - -/** - * Sample Lambda function which mocks the operation of checking the current price of a stock. - * For demonstration purposes this Lambda function simply returns a random integer between 0 and 100 as the stock price. - * - * @param {Object} event - Input event to the Lambda function - * @param {Object} context - Lambda Context runtime methods and attributes - * - * @returns {Object} object - Object containing the current price of the stock - * - */ -exports.lambdaHandler = async (event, context) => { - // Check current price of the stock - stock_price = getRandomInt(100) // Current stock price is mocked as a random integer between 0 and 100 - return { 'stock_price': stock_price } -}; diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/package.json b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/package.json deleted file mode 100644 index 056a8d808..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "stock_checker", - "version": "1.0.0", - "description": "Mock stock checker for NodeJS", - "main": "app.js", - "repository": "TODO", - "author": "SAM CLI", - "license": "MIT", - "dependencies": {}, - "scripts": { - "test": "mocha tests/unit/" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^9.1.4" - } -} diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/tests/unit/test-handler.js b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/tests/unit/test-handler.js deleted file mode 100644 index 72bbd7aa9..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-checker/tests/unit/test-handler.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -const app = require('../../app.js'); -const chai = require('chai'); -const expect = chai.expect; -var event, context; - -describe('Tests Stock Checker', function () { - it('Verifies response', async () => { - const result = await app.lambdaHandler(event, context) - - expect(result).to.be.an('object'); - expect(result.stock_price).to.be.an('number'); - expect(result.stock_price).to.be.at.least(0); - expect(result.stock_price).to.be.at.most(100); - }); -}); diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/.npmignore b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/.npmignore deleted file mode 100644 index e7e1fb04f..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/.npmignore +++ /dev/null @@ -1 +0,0 @@ -tests/* diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/app.js b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/app.js deleted file mode 100644 index c165a2852..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/app.js +++ /dev/null @@ -1,30 +0,0 @@ -const crypto = require("crypto"); - -function getRandomInt(max) { - return Math.floor(Math.random() * Math.floor(max)) + 1; -} - -/** - * Sample Lambda function which mocks the operation of selling a random number of shares for a stock. - * For demonstration purposes, this Lambda function does not actually perform any actual transactions. It simply returns a mocked result. - * - * @param {Object} event - Input event to the Lambda function - * @param {Object} context - Lambda Context runtime methods and attributes - * - * @returns {Object} object - Object containing details of the stock selling transaction - * - */ -exports.lambdaHandler = async (event, context) => { - // Get the price of the stock provided as input - stock_price = event["stock_price"] - var date = new Date(); - // Mocked result of a stock selling transaction - let transaction_result = { - 'id': crypto.randomBytes(16).toString("hex"), // Unique ID for the transaction - 'price': stock_price.toString(), // Price of each share - 'type': "sell", // Type of transaction(buy/ sell) - 'qty': getRandomInt(10).toString(), // Number of shares bought / sold(We are mocking this as a random integer between 1 and 10) - 'timestamp': date.toISOString(), // Timestamp of the when the transaction was completed - } - return transaction_result -}; diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/package.json b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/package.json deleted file mode 100644 index 056a8d808..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "stock_checker", - "version": "1.0.0", - "description": "Mock stock checker for NodeJS", - "main": "app.js", - "repository": "TODO", - "author": "SAM CLI", - "license": "MIT", - "dependencies": {}, - "scripts": { - "test": "mocha tests/unit/" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^9.1.4" - } -} diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/tests/unit/test-handler.js b/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/tests/unit/test-handler.js deleted file mode 100644 index f242250b1..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/functions/stock-seller/tests/unit/test-handler.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -const app = require('../../app.js'); -const chai = require('chai'); -const expect = chai.expect; -var event, context; - -describe('Tests Stock Seller', function () { - it('Verifies response', async () => { - event = { - 'stock_price': 75 - } - const result = await app.lambdaHandler(event, context) - - expect(result).to.be.an('object'); - expect(result).to.have.all.keys('id', 'price', 'type', 'timestamp', 'qty'); - expect(result.type).to.equal('sell'); - let qty = parseInt(result.qty); - expect(qty).to.be.at.least(1); - expect(qty).to.be.at.most(10); - }); -}); diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/makefile b/nodejs16.x/step-func/{{cookiecutter.project_name}}/makefile deleted file mode 100644 index 3e9440fd3..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/makefile +++ /dev/null @@ -1,71 +0,0 @@ -ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) - -run: - docker run -p 8083:8083 \ - --mount type=bind,readonly,source=$(ROOT_DIR)/statemachine/test/MockConfigFile.json,destination=/home/StepFunctionsLocal/MockConfigFile.json \ - -e SFN_MOCK_CONFIG="/home/StepFunctionsLocal/MockConfigFile.json" \ - amazon/aws-stepfunctions-local - -create: - sed -E -e 's/\$$\{.+\}/arn:aws:lambda:us-east-1:123456789012:function:mock/' statemachine/stock_trader.asl.json > statemachine/test/mocked.test.asl.json - aws stepfunctions create-state-machine \ - --endpoint-url http://localhost:8083 \ - --definition file://statemachine/test/mocked.test.asl.json \ - --name "StockTradingLocalTesting" \ - --role-arn "arn:aws:iam::123456789012:role/DummyRole" \ - --no-cli-pager - rm statemachine/test/mocked.test.asl.json - -happypathsellstocktest: - aws stepfunctions start-execution \ - --endpoint http://localhost:8083 \ - --name HappyPathSellStockTest \ - --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:StockTradingLocalTesting#HappyPathSellStockTest \ - --no-cli-pager - -happypathbuystocktest: - aws stepfunctions start-execution \ - --endpoint http://localhost:8083 \ - --name HappyPathBuyStockTest \ - --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:StockTradingLocalTesting#HappyPathBuyStockTest \ - --no-cli-pager - -checkstockerrorwithretry: - aws stepfunctions start-execution \ - --endpoint http://localhost:8083 \ - --name checkStockErrorExecution \ - --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:StockTradingLocalTesting#CheckStockRetryOnServiceExceptionTest \ - --no-cli-pager - -sellstockerrorwithretry: - aws stepfunctions start-execution \ - --endpoint http://localhost:8083 \ - --name sellStockErrorExecution \ - --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:StockTradingLocalTesting#SellStockRetryOnServiceExceptionTest \ - --no-cli-pager - - -all: create happypathsellstocktest happypathbuystocktest checkstockerrorwithretry sellstockerrorwithretry - -happypathsellstocktest-h: - aws stepfunctions get-execution-history \ - --endpoint http://localhost:8083 \ - --execution-arn arn:aws:states:us-east-1:123456789012:execution:StockTradingLocalTesting:HappyPathSellStockTest \ - --query 'events[?type==`TaskStateExited` && stateExitedEventDetails.name==`Record Transaction`]' \ - --no-cli-pager - -checkstockerror: - aws stepfunctions get-execution-history \ - --endpoint http://localhost:8083 \ - --execution-arn arn:aws:states:us-east-1:123456789012:execution:StockTradingLocalTesting:checkStockErrorExecution \ - --query 'events[?type==`TaskStateExited` && stateExitedEventDetails.name==`Record Transaction` ]' \ - --no-cli-pager - -sellstockerror: - aws stepfunctions get-execution-history \ - --endpoint http://localhost:8083 \ - --execution-arn arn:aws:states:us-east-1:123456789012:execution:StockTradingLocalTesting:sellStockErrorExecution \ - --query 'events[?type==`TaskStateExited` && stateExitedEventDetails.name==`Record Transaction` ]' \ - --no-cli-pager - -history: happypathsellstocktest-h checkstockerror sellstockerror \ No newline at end of file diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/statemachine/stock_trader.asl.json b/nodejs16.x/step-func/{{cookiecutter.project_name}}/statemachine/stock_trader.asl.json deleted file mode 100644 index c29281b34..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/statemachine/stock_trader.asl.json +++ /dev/null @@ -1,97 +0,0 @@ -{ - "Comment": "A state machine that does mock stock trading.", - "StartAt": "Check Stock Value", - "States": { - "Check Stock Value": { - "Type": "Task", - "Resource": "${StockCheckerFunctionArn}", - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 15, - "MaxAttempts": 5, - "BackoffRate": 1.5 - } - ], - "Next": "Buy or Sell?" - }, - "Buy or Sell?": { - "Type": "Choice", - "Choices": [ - { - "Variable": "$.stock_price", - "NumericLessThanEquals": 50, - "Next": "Buy Stock" - } - ], - "Default": "Sell Stock" - }, - "Sell Stock": { - "Type": "Task", - "Resource": "${StockSellerFunctionArn}", - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 2, - "MaxAttempts": 3, - "BackoffRate": 1 - } - ], - "Next": "Record Transaction" - }, - "Buy Stock": { - "Type": "Task", - "Resource": "${StockBuyerFunctionArn}", - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 2, - "MaxAttempts": 3, - "BackoffRate": 1 - } - ], - "Next": "Record Transaction" - }, - "Record Transaction": { - "Type": "Task", - "Resource": "${DDBPutItem}", - "Parameters": { - "TableName": "${DDBTable}", - "Item": { - "Id": { - "S.$": "$.id" - }, - "Type": { - "S.$": "$.type" - }, - "Price": { - "N.$": "$.price" - }, - "Quantity": { - "N.$": "$.qty" - }, - "Timestamp": { - "S.$": "$.timestamp" - } - } - }, - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 20, - "MaxAttempts": 5, - "BackoffRate": 10 - } - ], - "End": true - } - } -} \ No newline at end of file diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/statemachine/test/MockConfigFile.json b/nodejs16.x/step-func/{{cookiecutter.project_name}}/statemachine/test/MockConfigFile.json deleted file mode 100644 index 20db6d24c..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/statemachine/test/MockConfigFile.json +++ /dev/null @@ -1,142 +0,0 @@ -{ - "StateMachines": { - "StockTradingLocalTesting": { - "TestCases": { - "HappyPathSellStockTest": { - "Check Stock Value": "LambdaMockedSuccessValueGreaterThan50", - "Sell Stock": "SellStockLambdaMockedResponse", - "Record Transaction": "RecordTransactionDDBMockedResponse" - }, - "HappyPathBuyStockTest": { - "Check Stock Value": "LambdaMockedSuccessValueLowerThan50", - "Buy Stock": "BuyStockLambdaMockedResponse", - "Record Transaction": "RecordTransactionDDBMockedResponse" - }, - "CheckStockRetryOnServiceExceptionTest": { - "Check Stock Value": "CheckStockLambdaMockedRetryWithSuccess", - "Sell Stock": "SellStockLambdaMockedResponse", - "Record Transaction": "RecordTransactionDDBMockedResponse" - }, - "SellStockRetryOnServiceExceptionTest": { - "Check Stock Value": "LambdaMockedSuccessValueGreaterThan50", - "Sell Stock": "SellStockLambdaMockedRetryWithSuccess", - "Record Transaction": "RecordTransactionDDBMockedResponse" - } - } - } - }, - "MockedResponses": { - "LambdaMockedSuccessValueGreaterThan50": { - "0": { - "Return": { - "stock_price": 98 - } - } - }, - "LambdaMockedSuccessValueLowerThan50": { - "0": { - "Return": { - "stock_price": 32 - } - } - }, - "SellStockLambdaMockedResponse": { - "0": { - "Return": { - "id": "8cd8e4d92fe716b7cedff5636ab9d24e", - "price": "98", - "type": "sell", - "qty": "7", - "timestamp": "2022-06-22T21:14:18.228Z" - } - } - }, - "BuyStockLambdaMockedResponse": { - "0": { - "Return": { - "id": "8cd8e4d92fe716b7cedff5636ab9d24e", - "price": "32", - "type": "buy", - "qty": "7", - "timestamp": "2022-06-22T21:14:18.228Z" - } - } - }, - "RecordTransactionDDBMockedResponse": { - "0": { - "Return": { - "resourceType": "dynamodb", - "resource": "putItem", - "output": { - "SdkHttpMetadata": { - "AllHttpHeaders": { - "Server": [ - "Server" - ], - "Connection": [ - "keep-alive" - ], - "x-amzn-RequestId": [ - "LAT641GUVNBRI0DC1HC6S4MDH3VV4KQNSO5AEMVJF66Q9ASUAAJG" - ], - "x-amz-crc32": [ - "2745614147" - ], - "Content-Length": [ - "2" - ], - "Date": [ - "Wed, 22 Jun 2022 21:14:18 GMT" - ], - "Content-Type": [ - "application/x-amz-json-1.0" - ] - }, - "HttpHeaders": { - "Connection": "keep-alive", - "Content-Length": "2", - "Content-Type": "application/x-amz-json-1.0", - "Date": "Wed, 22 Jun 2022 21:14:18 GMT", - "Server": "Server", - "x-amz-crc32": "2745614147", - "x-amzn-RequestId": "LAT641GUVNBRI0DC1HC6S4MDH3VV4KQNSO5AEMVJF66Q9ASUAAJG" - }, - "HttpStatusCode": 200 - }, - "SdkResponseMetadata": { - "RequestId": "LAT641GUVNBRI0DC1HC6S4MDH3VV4KQNSO5AEMVJF66Q9ASUAAJG" - } - } - } - } - }, - "CheckStockLambdaMockedRetryWithSuccess": { - "0-2": { - "Throw": { - "Error": "States.TaskFailed" - } - }, - "3": { - "Return": { - "stock_price": 89 - } - } - }, - "SellStockLambdaMockedRetryWithSuccess": { - "0-2": { - "Throw": { - "Error": "States.TaskFailed" - } - }, - "3": { - "Return": { - "id": "8cd8e4d92fe716b7cedff5636ab9d24e", - "price": "98", - "type": "sell", - "qty": "5", - "timestamp": "2022-06-22T21:14:18.228Z" - } - } - } - } -} \ No newline at end of file diff --git a/nodejs16.x/step-func/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/step-func/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index d956b31d3..000000000 --- a/nodejs16.x/step-func/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,94 +0,0 @@ -AWSTemplateFormatVersion: "2010-09-09" -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - - Sample SAM Template for {{ cookiecutter.project_name }} - -Resources: - StockTradingStateMachine: - Type: AWS::Serverless::StateMachine # More info about State Machine Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html - Properties: - DefinitionUri: statemachine/stock_trader.asl.json - DefinitionSubstitutions: - StockCheckerFunctionArn: !GetAtt StockCheckerFunction.Arn - StockSellerFunctionArn: !GetAtt StockSellerFunction.Arn - StockBuyerFunctionArn: !GetAtt StockBuyerFunction.Arn - DDBPutItem: !Sub arn:${AWS::Partition}:states:::dynamodb:putItem - DDBTable: !Ref TransactionTable - Events: - HourlyTradingSchedule: - Type: Schedule # More info about Schedule Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-schedule.html - Properties: - Description: Schedule to run the stock trading state machine every hour - Enabled: False # This schedule is disabled by default to avoid incurring charges. - Schedule: "rate(1 hour)" - Policies: # Find out more about SAM policy templates: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html - - LambdaInvokePolicy: - FunctionName: !Ref StockCheckerFunction - - LambdaInvokePolicy: - FunctionName: !Ref StockSellerFunction - - LambdaInvokePolicy: - FunctionName: !Ref StockBuyerFunction - - DynamoDBWritePolicy: - TableName: !Ref TransactionTable - - StockCheckerFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html - Properties: - CodeUri: functions/stock-checker/ - Handler: app.lambdaHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - - StockSellerFunction: - Type: AWS::Serverless::Function - Properties: - CodeUri: functions/stock-seller/ - Handler: app.lambdaHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - - StockBuyerFunction: - Type: AWS::Serverless::Function - Properties: - CodeUri: functions/stock-buyer/ - Handler: app.lambdaHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - - TransactionTable: - Type: AWS::Serverless::SimpleTable # More info about SimpleTable Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-simpletable.html - Properties: - PrimaryKey: - Name: Id - Type: String - ProvisionedThroughput: - ReadCapacityUnits: 1 - WriteCapacityUnits: 1 - -Outputs: - # StockTradingStateMachineHourlyTradingSchedule is an implicit Schedule event rule created out of Events key under Serverless::StateMachine - # Find out more about other implicit resources you can reference within SAM - # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html - StockTradingStateMachineArn: - Description: "Stock Trading state machine ARN" - Value: !Ref StockTradingStateMachine - StockTradingStateMachineRole: - Description: "IAM Role created for Stock Trading state machine based on the specified SAM Policy Templates" - Value: !GetAtt StockTradingStateMachineRole.Arn diff --git a/nodejs16.x/web-conn/.gitignore b/nodejs16.x/web-conn/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/web-conn/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/web-conn/README.md b/nodejs16.x/web-conn/README.md deleted file mode 100644 index e2aa624ac..000000000 --- a/nodejs16.x/web-conn/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS Quick Start Web Application - -A cookiecutter template to create a NodeJS Quick Start Web Application using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x --app-template hello-world-connector --name web-app` - -> **NOTE**: ``--name`` allows you to specify a different project folder name - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/web-conn/cookiecutter.json b/nodejs16.x/web-conn/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/web-conn/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/web-conn/setup.cfg b/nodejs16.x/web-conn/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/web-conn/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 3c3629e64..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/README.md b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 923c7c670..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,160 +0,0 @@ -# {{cookiecutter.project_name}} - -This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) command line interface (CLI). It includes the following files and folders: - -- `src` - Code for the application's Lambda function. -- `events` - Invocation events that you can use to invoke the function. -- `__tests__` - Unit tests for the application code. -- `template.yaml` - A template that defines the application's AWS resources. - -The application uses several AWS resources, including Lambda functions, an API Gateway API, and Amazon DynamoDB tables. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open-source plugin for popular IDEs that uses the AWS SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds step-through debugging for Lambda function code. - -To get started, see the following: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The AWS SAM CLI is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the AWS SAM CLI, you need the following tools: - -* AWS SAM CLI - [Install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html). -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the npm package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community). - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -The API Gateway endpoint API will be displayed in the outputs when the deployment is complete. - -## Use the AWS SAM CLI to build and test locally - -Build your application by using the `sam build` command. - -```bash -my-application$ sam build -``` - -The AWS SAM CLI installs dependencies that are defined in `package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -my-application$ sam local invoke putItemFunction --event events/event-post-item.json -my-application$ sam local invoke getAllItemsFunction --event events/event-get-all-items.json -``` - -The AWS SAM CLI can also emulate your application's API. Use the `sam local start-api` command to run the API locally on port 3000. - -```bash -my-application$ sam local start-api -my-application$ curl http://localhost:3000/ -``` - -The AWS 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. - -```yaml - Events: - Api: - Type: Api - Properties: - Path: / - Method: GET -``` - -## Add a resource to your application -The application template uses 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 that aren't included in the [AWS SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use the standard [AWS CloudFormation resource types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html). - -Update `template.yaml` to add a dead-letter queue to your application. In the **Resources** section, add a resource named **MyQueue** with the type **AWS::SQS::Queue**. Then add a property to the **AWS::Serverless::Function** resource named **DeadLetterQueue** that targets the queue's Amazon Resource Name (ARN), and a policy that grants the function permission to access the queue. - -``` -Resources: - MyQueue: - Type: AWS::SQS::Queue - getAllItemsFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x - DeadLetterQueue: - Type: SQS - TargetArn: !GetAtt MyQueue.Arn - Policies: - - SQSSendMessagePolicy: - QueueName: !GetAtt MyQueue.QueueName -``` - -The dead-letter queue is a location for Lambda to send events that could not be processed. It's only used if you invoke your function asynchronously, but it's useful here to show how you can modify your application's resources and function configuration. - -Deploy the updated application. - -```bash -my-application$ sam deploy -``` - -Open the [**Applications**](https://console.aws.amazon.com/lambda/home#/applications) page of the Lambda console, and choose your application. When the deployment completes, view the application resources on the **Overview** tab to see the new resource. Then, choose the function to see the updated configuration that specifies the dead-letter queue. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, the AWS SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs that are generated by your 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. - -**NOTE:** This command works for all Lambda functions, not just the ones you deploy using AWS SAM. - -```bash -my-application$ sam logs -n putItemFunction --stack-name sam-app --tail -``` - -**NOTE:** This uses the logical name of the function within the stack. This is the correct name to use when searching logs inside an AWS Lambda function within a CloudFormation stack, even if the deployed function name varies due to CloudFormation's unique resource name generation. - -You can find more information and examples about filtering Lambda function logs in the [AWS SAM CLI documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -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. - -```bash -my-application$ npm install -my-application$ npm run test -``` - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the [AWS SAM Developer Guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html). - -Next, you can use the AWS Serverless Application Repository to deploy ready-to-use apps that go beyond Hello World samples and learn how authors developed their applications. For more information, see the [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) and the [AWS Serverless Application Repository Developer Guide](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html). diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-all-items.test.js b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-all-items.test.js deleted file mode 100644 index 4200ce8b4..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-all-items.test.js +++ /dev/null @@ -1,45 +0,0 @@ -// Import all functions from get-all-items.js -const lambda = require('../../../src/handlers/get-all-items.js'); -// Import dynamodb from aws-sdk -const dynamodb = require('aws-sdk/clients/dynamodb'); - -// This includes all tests for getAllItemsHandler() -describe('Test getAllItemsHandler', () => { - let scanSpy; - - // Test one-time setup and teardown, see more in https://jestjs.io/docs/en/setup-teardown - beforeAll(() => { - // Mock dynamodb get and put methods - // https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname - scanSpy = jest.spyOn(dynamodb.DocumentClient.prototype, 'scan'); - }); - - // Clean up mocks - afterAll(() => { - scanSpy.mockRestore(); - }); - - it('should return ids', async () => { - const items = [{ id: 'id1' }, { id: 'id2' }]; - - // Return the specified value whenever the spied scan function is called - scanSpy.mockReturnValue({ - promise: () => Promise.resolve({ Items: items }) - }); - - const event = { - httpMethod: 'GET' - } - - // Invoke helloFromLambdaHandler() - const result = await lambda.getAllItemsHandler(event); - - const expectedResult = { - statusCode: 200, - body: JSON.stringify(items) - }; - - // Compare the result with the expected result - expect(result).toEqual(expectedResult); - }); -}); diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-by-id.test.js b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-by-id.test.js deleted file mode 100644 index 9a95c6ca9..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-by-id.test.js +++ /dev/null @@ -1,50 +0,0 @@ -// Import all functions from get-by-id.js -const lambda = require('../../../src/handlers/get-by-id.js'); -// Import dynamodb from aws-sdk -const dynamodb = require('aws-sdk/clients/dynamodb'); - -// This includes all tests for getByIdHandler() -describe('Test getByIdHandler', () => { - let getSpy; - - // Test one-time setup and teardown, see more in https://jestjs.io/docs/en/setup-teardown - beforeAll(() => { - // Mock dynamodb get and put methods - // https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname - getSpy = jest.spyOn(dynamodb.DocumentClient.prototype, 'get'); - }); - - // Clean up mocks - afterAll(() => { - getSpy.mockRestore(); - }); - - // This test invokes getByIdHandler() and compare the result - it('should get item by id', async () => { - const item = { id: 'id1' }; - - // Return the specified value whenever the spied get function is called - getSpy.mockReturnValue({ - promise: () => Promise.resolve({ Item: item }) - }); - - const event = { - httpMethod: 'GET', - pathParameters: { - id: 'id1' - } - } - - // Invoke getByIdHandler() - const result = await lambda.getByIdHandler(event); - - const expectedResult = { - statusCode: 200, - body: JSON.stringify(item) - }; - - // Compare the result with the expected result - expect(result).toEqual(expectedResult); - }); -}); - \ No newline at end of file diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/put-item.test.js b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/put-item.test.js deleted file mode 100644 index 5d66149e4..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/__tests__/unit/handlers/put-item.test.js +++ /dev/null @@ -1,47 +0,0 @@ -// Import all functions from put-item.js -const lambda = require('../../../src/handlers/put-item.js'); -// Import dynamodb from aws-sdk -const dynamodb = require('aws-sdk/clients/dynamodb'); - -// This includes all tests for putItemHandler() -describe('Test putItemHandler', function () { - let putSpy; - - // Test one-time setup and teardown, see more in https://jestjs.io/docs/en/setup-teardown - beforeAll(() => { - // Mock dynamodb get and put methods - // https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname - putSpy = jest.spyOn(dynamodb.DocumentClient.prototype, 'put'); - }); - - // Clean up mocks - afterAll(() => { - putSpy.mockRestore(); - }); - - // This test invokes putItemHandler() and compare the result - it('should add id to the table', async () => { - const returnedItem = { id: 'id1', name: 'name1' }; - - // Return the specified value whenever the spied put function is called - putSpy.mockReturnValue({ - promise: () => Promise.resolve(returnedItem) - }); - - const event = { - httpMethod: 'POST', - body: '{"id": "id1","name": "name1"}' - }; - - // Invoke putItemHandler() - const result = await lambda.putItemHandler(event); - const expectedResult = { - statusCode: 200, - body: JSON.stringify(returnedItem) - }; - - // Compare the result with the expected result - expect(result).toEqual(expectedResult); - }); -}); - \ No newline at end of file diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/buildspec.yml b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/buildspec.yml deleted file mode 100644 index 7c1dae85e..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/buildspec.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: 0.2 -phases: - install: - commands: - # Install all dependencies (including dependencies for running tests) - - npm install - pre_build: - commands: - # Discover and run unit tests in the '__tests__' directory - - npm run test - # Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda - - rm -rf ./__tests__ - # Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json) - - npm prune --production - build: - commands: - # Use AWS SAM to package the application by using AWS CloudFormation - - aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --output-template template-export.yml -artifacts: - type: zip - files: - - template-export.yml diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/env.json b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/env.json deleted file mode 100644 index c6073eb26..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/env.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "getAllItemsFunction": { - "SAMPLE_TABLE": "" - }, - "getByIdFunction": { - "SAMPLE_TABLE": "" - }, - "putItemFunction": { - "SAMPLE_TABLE": "" - } - } \ No newline at end of file diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-get-all-items.json b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-get-all-items.json deleted file mode 100644 index 3a0cb5f77..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-get-all-items.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "httpMethod": "GET" -} \ No newline at end of file diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-get-by-id.json b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-get-by-id.json deleted file mode 100644 index 63a64fb45..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-get-by-id.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "httpMethod": "GET", - "pathParameters": { - "id": "id1" - } -} \ No newline at end of file diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-post-item.json b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-post-item.json deleted file mode 100644 index 6367003e5..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/events/event-post-item.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "httpMethod": "POST", - "body": "{\"id\": \"id1\",\"name\": \"name1\"}" -} \ No newline at end of file diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/package.json b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/package.json deleted file mode 100644 index bbf417af9..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "delete-test-01", - "description": "delete-test-01-description", - "version": "0.0.1", - "private": true, - "dependencies": { - "aws-sdk": "^2.799.0" - }, - "devDependencies": { - "jest": "^26.6.3" - }, - "scripts": { - "test": "jest" - } -} - diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/get-all-items.js b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/get-all-items.js deleted file mode 100644 index 07d23886d..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/get-all-items.js +++ /dev/null @@ -1,37 +0,0 @@ -// Create clients and set shared const values outside of the handler. - -// Get the DynamoDB table name from environment variables -const tableName = process.env.SAMPLE_TABLE; - -// Create a DocumentClient that represents the query to add an item -const dynamodb = require('aws-sdk/clients/dynamodb'); -const docClient = new dynamodb.DocumentClient(); - -/** - * A simple example includes a HTTP get method to get all items from a DynamoDB table. - */ -exports.getAllItemsHandler = async (event) => { - if (event.httpMethod !== 'GET') { - throw new Error(`getAllItems only accept GET method, you tried: ${event.httpMethod}`); - } - // All log statements are written to CloudWatch - console.info('received:', event); - - // get all items from the table (only first 1MB data, you can use `LastEvaluatedKey` to get the rest of data) - // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#scan-property - // https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html - var params = { - TableName : tableName - }; - const data = await docClient.scan(params).promise(); - const items = data.Items; - - const response = { - statusCode: 200, - body: JSON.stringify(items) - }; - - // All log statements are written to CloudWatch - console.info(`response from: ${event.path} statusCode: ${response.statusCode} body: ${response.body}`); - return response; -} diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/get-by-id.js b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/get-by-id.js deleted file mode 100644 index 117407e79..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/get-by-id.js +++ /dev/null @@ -1,40 +0,0 @@ -// Create clients and set shared const values outside of the handler. - -// Get the DynamoDB table name from environment variables -const tableName = process.env.SAMPLE_TABLE; - -// Create a DocumentClient that represents the query to add an item -const dynamodb = require('aws-sdk/clients/dynamodb'); -const docClient = new dynamodb.DocumentClient(); - -/** - * A simple example includes a HTTP get method to get one item by id from a DynamoDB table. - */ -exports.getByIdHandler = async (event) => { - if (event.httpMethod !== 'GET') { - throw new Error(`getMethod only accept GET method, you tried: ${event.httpMethod}`); - } - // All log statements are written to CloudWatch - console.info('received:', event); - - // Get id from pathParameters from APIGateway because of `/{id}` at template.yaml - const id = event.pathParameters.id; - - // Get the item from the table - // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#get-property - var params = { - TableName : tableName, - Key: { id: id }, - }; - const data = await docClient.get(params).promise(); - const item = data.Item; - - const response = { - statusCode: 200, - body: JSON.stringify(item) - }; - - // All log statements are written to CloudWatch - console.info(`response from: ${event.path} statusCode: ${response.statusCode} body: ${response.body}`); - return response; -} diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/put-item.js b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/put-item.js deleted file mode 100644 index 35997c8c9..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/src/handlers/put-item.js +++ /dev/null @@ -1,42 +0,0 @@ -// Create clients and set shared const values outside of the handler. - -// Create a DocumentClient that represents the query to add an item -const dynamodb = require('aws-sdk/clients/dynamodb'); -const docClient = new dynamodb.DocumentClient(); - -// Get the DynamoDB table name from environment variables -const tableName = process.env.SAMPLE_TABLE; - -/** - * A simple example includes a HTTP post method to add one item to a DynamoDB table. - */ -exports.putItemHandler = async (event) => { - if (event.httpMethod !== 'POST') { - throw new Error(`postMethod only accepts POST method, you tried: ${event.httpMethod} method.`); - } - // All log statements are written to CloudWatch - console.info('received:', event); - - // Get id and name from the body of the request - const body = JSON.parse(event.body); - const id = body.id; - const name = body.name; - - // Creates a new item, or replaces an old item with a new item - // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#put-property - var params = { - TableName : tableName, - Item: { id : id, name: name } - }; - - const result = await docClient.put(params).promise(); - - const response = { - statusCode: 200, - body: JSON.stringify(body) - }; - - // All log statements are written to CloudWatch - console.info(`response from: ${event.path} statusCode: ${response.statusCode} body: ${response.body}`); - return response; -}; diff --git a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/web-conn/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index f07637335..000000000 --- a/nodejs16.x/web-conn/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,131 +0,0 @@ -# This is the SAM template that represents the architecture of your serverless application -# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html - -# The AWSTemplateFormatVersion identifies the capabilities of the template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html -AWSTemplateFormatVersion: 2010-09-09 -Description: >- - {{cookiecutter.project_name}} - -# Transform section specifies one or more macros that AWS CloudFormation uses to process your template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html -Transform: -- AWS::Serverless-2016-10-31 - -# Resources declares the AWS resources that you want to include in the stack -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html -Resources: - getAllItemsFunctionToTableConnector: - Type: AWS::Serverless::Connector # More info about Connector Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-connector.html - Properties: - Source: - Id: getAllItemsFunction - Destination: - Id: SampleTable - Permissions: - - Read - - getByIdFunctionToTableConnector: - Type: AWS::Serverless::Connector - Properties: - Source: - Id: getByIdFunction - Destination: - Id: SampleTable - Permissions: - - Read - - putItemFunctionToTableConnector: - Type: AWS::Serverless::Connector - Properties: - Source: - Id: putItemFunction - Destination: - Id: SampleTable - Permissions: - - Write - - # Each Lambda function is defined by properties: - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - - # This is a Lambda function config associated with the source code: get-all-items.js - getAllItemsFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x - MemorySize: 128 - Timeout: 100 - Description: A simple example includes a HTTP get method to get all items from a DynamoDB table. - Environment: - Variables: - # Make table name accessible as environment variable from function code during execution - SAMPLE_TABLE: !Ref SampleTable - Events: - Api: - Type: Api - Properties: - Path: / - Method: GET - # Each Lambda function is defined by properties: - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - - # This is a Lambda function config associated with the source code: get-by-id.js - getByIdFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/get-by-id.getByIdHandler - Runtime: nodejs16.x - MemorySize: 128 - Timeout: 100 - Description: A simple example includes a HTTP get method to get one item by id from a DynamoDB table. - Environment: - Variables: - # Make table name accessible as environment variable from function code during execution - SAMPLE_TABLE: !Ref SampleTable - Events: - Api: - Type: Api - Properties: - Path: /{id} - Method: GET - # Each Lambda function is defined by properties: - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - - # This is a Lambda function config associated with the source code: put-item.js - putItemFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/put-item.putItemHandler - Runtime: nodejs16.x - MemorySize: 128 - Timeout: 100 - Description: A simple example includes a HTTP post method to add one item to a DynamoDB table. - Environment: - Variables: - # Make table name accessible as environment variable from function code during execution - SAMPLE_TABLE: !Ref SampleTable - Events: - Api: - Type: Api - Properties: - Path: / - Method: POST - # Simple syntax to create a DynamoDB table with a single attribute primary key, more in - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesssimpletable - - # DynamoDB table to store item: {id: <ID>, name: <NAME>} - SampleTable: - Type: AWS::Serverless::SimpleTable - Properties: - PrimaryKey: - Name: id - Type: String - ProvisionedThroughput: - ReadCapacityUnits: 2 - WriteCapacityUnits: 2 - -Outputs: - WebEndpoint: - Description: "API Gateway endpoint URL for Prod stage" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/" diff --git a/nodejs16.x/web/.gitignore b/nodejs16.x/web/.gitignore deleted file mode 100644 index 41bcace31..000000000 --- a/nodejs16.x/web/.gitignore +++ /dev/null @@ -1,229 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam -# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,python,windows,sam - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -pytestdebug.log - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ -doc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -#poetry.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -# .env -.env/ -.venv/ -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -pythonenv* - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# operating system-related files -# file properties cache/storage on macOS -*.DS_Store -# thumbnail cache on Windows -Thumbs.db - -# profiling data -.prof - - -### SAM ### -# Ignore build directories for the AWS Serverless Application Model (SAM) -# Info: https://aws.amazon.com/serverless/sam/ -# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html - -**/.aws-sam - -### Windows ### -# Windows thumbnail cache files -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/osx,linux,python,windows,sam diff --git a/nodejs16.x/web/README.md b/nodejs16.x/web/README.md deleted file mode 100644 index b96206ce3..000000000 --- a/nodejs16.x/web/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Cookiecutter NodeJS Quick Start Web Application - -A cookiecutter template to create a NodeJS Quick Start Web Application using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Generate a boilerplate template in your current project directory using the following syntax: - -* **NodeJS 16**: `sam init --runtime nodejs16.x --app-template quick-start-web --name web-app` - -> **NOTE**: ``--name`` allows you to specify a different project folder name - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) - diff --git a/nodejs16.x/web/cookiecutter.json b/nodejs16.x/web/cookiecutter.json deleted file mode 100644 index 7d105b63f..000000000 --- a/nodejs16.x/web/cookiecutter.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "nodejs16.x", - "architectures": { - "value": [ - "x86_64", "arm64" - ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/nodejs16.x/web/setup.cfg b/nodejs16.x/web/setup.cfg deleted file mode 100644 index eee4ab11a..000000000 --- a/nodejs16.x/web/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -prefix= \ No newline at end of file diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/.gitignore b/nodejs16.x/web/{{cookiecutter.project_name}}/.gitignore deleted file mode 100644 index 3c3629e64..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/README.md b/nodejs16.x/web/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 923c7c670..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,160 +0,0 @@ -# {{cookiecutter.project_name}} - -This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) command line interface (CLI). It includes the following files and folders: - -- `src` - Code for the application's Lambda function. -- `events` - Invocation events that you can use to invoke the function. -- `__tests__` - Unit tests for the application code. -- `template.yaml` - A template that defines the application's AWS resources. - -The application uses several AWS resources, including Lambda functions, an API Gateway API, and Amazon DynamoDB tables. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open-source plugin for popular IDEs that uses the AWS SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds step-through debugging for Lambda function code. - -To get started, see the following: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The AWS SAM CLI is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API. - -To use the AWS SAM CLI, you need the following tools: - -* AWS SAM CLI - [Install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html). -* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the npm package management tool. -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community). - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -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: - -* **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. -* **AWS Region**: The AWS region you want to deploy your app to. -* **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. -* **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. -* **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. - -The API Gateway endpoint API will be displayed in the outputs when the deployment is complete. - -## Use the AWS SAM CLI to build and test locally - -Build your application by using the `sam build` command. - -```bash -my-application$ sam build -``` - -The AWS SAM CLI installs dependencies that are defined in `package.json`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -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. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -my-application$ sam local invoke putItemFunction --event events/event-post-item.json -my-application$ sam local invoke getAllItemsFunction --event events/event-get-all-items.json -``` - -The AWS SAM CLI can also emulate your application's API. Use the `sam local start-api` command to run the API locally on port 3000. - -```bash -my-application$ sam local start-api -my-application$ curl http://localhost:3000/ -``` - -The AWS 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. - -```yaml - Events: - Api: - Type: Api - Properties: - Path: / - Method: GET -``` - -## Add a resource to your application -The application template uses 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 that aren't included in the [AWS SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use the standard [AWS CloudFormation resource types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html). - -Update `template.yaml` to add a dead-letter queue to your application. In the **Resources** section, add a resource named **MyQueue** with the type **AWS::SQS::Queue**. Then add a property to the **AWS::Serverless::Function** resource named **DeadLetterQueue** that targets the queue's Amazon Resource Name (ARN), and a policy that grants the function permission to access the queue. - -``` -Resources: - MyQueue: - Type: AWS::SQS::Queue - getAllItemsFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x - DeadLetterQueue: - Type: SQS - TargetArn: !GetAtt MyQueue.Arn - Policies: - - SQSSendMessagePolicy: - QueueName: !GetAtt MyQueue.QueueName -``` - -The dead-letter queue is a location for Lambda to send events that could not be processed. It's only used if you invoke your function asynchronously, but it's useful here to show how you can modify your application's resources and function configuration. - -Deploy the updated application. - -```bash -my-application$ sam deploy -``` - -Open the [**Applications**](https://console.aws.amazon.com/lambda/home#/applications) page of the Lambda console, and choose your application. When the deployment completes, view the application resources on the **Overview** tab to see the new resource. Then, choose the function to see the updated configuration that specifies the dead-letter queue. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, the AWS SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs that are generated by your 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. - -**NOTE:** This command works for all Lambda functions, not just the ones you deploy using AWS SAM. - -```bash -my-application$ sam logs -n putItemFunction --stack-name sam-app --tail -``` - -**NOTE:** This uses the logical name of the function within the stack. This is the correct name to use when searching logs inside an AWS Lambda function within a CloudFormation stack, even if the deployed function name varies due to CloudFormation's unique resource name generation. - -You can find more information and examples about filtering Lambda function logs in the [AWS SAM CLI documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -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. - -```bash -my-application$ npm install -my-application$ npm run test -``` - -## Cleanup - -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: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the [AWS SAM Developer Guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html). - -Next, you can use the AWS Serverless Application Repository to deploy ready-to-use apps that go beyond Hello World samples and learn how authors developed their applications. For more information, see the [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) and the [AWS Serverless Application Repository Developer Guide](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html). diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-all-items.test.js b/nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-all-items.test.js deleted file mode 100644 index 4200ce8b4..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-all-items.test.js +++ /dev/null @@ -1,45 +0,0 @@ -// Import all functions from get-all-items.js -const lambda = require('../../../src/handlers/get-all-items.js'); -// Import dynamodb from aws-sdk -const dynamodb = require('aws-sdk/clients/dynamodb'); - -// This includes all tests for getAllItemsHandler() -describe('Test getAllItemsHandler', () => { - let scanSpy; - - // Test one-time setup and teardown, see more in https://jestjs.io/docs/en/setup-teardown - beforeAll(() => { - // Mock dynamodb get and put methods - // https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname - scanSpy = jest.spyOn(dynamodb.DocumentClient.prototype, 'scan'); - }); - - // Clean up mocks - afterAll(() => { - scanSpy.mockRestore(); - }); - - it('should return ids', async () => { - const items = [{ id: 'id1' }, { id: 'id2' }]; - - // Return the specified value whenever the spied scan function is called - scanSpy.mockReturnValue({ - promise: () => Promise.resolve({ Items: items }) - }); - - const event = { - httpMethod: 'GET' - } - - // Invoke helloFromLambdaHandler() - const result = await lambda.getAllItemsHandler(event); - - const expectedResult = { - statusCode: 200, - body: JSON.stringify(items) - }; - - // Compare the result with the expected result - expect(result).toEqual(expectedResult); - }); -}); diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-by-id.test.js b/nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-by-id.test.js deleted file mode 100644 index 9a95c6ca9..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/get-by-id.test.js +++ /dev/null @@ -1,50 +0,0 @@ -// Import all functions from get-by-id.js -const lambda = require('../../../src/handlers/get-by-id.js'); -// Import dynamodb from aws-sdk -const dynamodb = require('aws-sdk/clients/dynamodb'); - -// This includes all tests for getByIdHandler() -describe('Test getByIdHandler', () => { - let getSpy; - - // Test one-time setup and teardown, see more in https://jestjs.io/docs/en/setup-teardown - beforeAll(() => { - // Mock dynamodb get and put methods - // https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname - getSpy = jest.spyOn(dynamodb.DocumentClient.prototype, 'get'); - }); - - // Clean up mocks - afterAll(() => { - getSpy.mockRestore(); - }); - - // This test invokes getByIdHandler() and compare the result - it('should get item by id', async () => { - const item = { id: 'id1' }; - - // Return the specified value whenever the spied get function is called - getSpy.mockReturnValue({ - promise: () => Promise.resolve({ Item: item }) - }); - - const event = { - httpMethod: 'GET', - pathParameters: { - id: 'id1' - } - } - - // Invoke getByIdHandler() - const result = await lambda.getByIdHandler(event); - - const expectedResult = { - statusCode: 200, - body: JSON.stringify(item) - }; - - // Compare the result with the expected result - expect(result).toEqual(expectedResult); - }); -}); - \ No newline at end of file diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/put-item.test.js b/nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/put-item.test.js deleted file mode 100644 index 5d66149e4..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/__tests__/unit/handlers/put-item.test.js +++ /dev/null @@ -1,47 +0,0 @@ -// Import all functions from put-item.js -const lambda = require('../../../src/handlers/put-item.js'); -// Import dynamodb from aws-sdk -const dynamodb = require('aws-sdk/clients/dynamodb'); - -// This includes all tests for putItemHandler() -describe('Test putItemHandler', function () { - let putSpy; - - // Test one-time setup and teardown, see more in https://jestjs.io/docs/en/setup-teardown - beforeAll(() => { - // Mock dynamodb get and put methods - // https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname - putSpy = jest.spyOn(dynamodb.DocumentClient.prototype, 'put'); - }); - - // Clean up mocks - afterAll(() => { - putSpy.mockRestore(); - }); - - // This test invokes putItemHandler() and compare the result - it('should add id to the table', async () => { - const returnedItem = { id: 'id1', name: 'name1' }; - - // Return the specified value whenever the spied put function is called - putSpy.mockReturnValue({ - promise: () => Promise.resolve(returnedItem) - }); - - const event = { - httpMethod: 'POST', - body: '{"id": "id1","name": "name1"}' - }; - - // Invoke putItemHandler() - const result = await lambda.putItemHandler(event); - const expectedResult = { - statusCode: 200, - body: JSON.stringify(returnedItem) - }; - - // Compare the result with the expected result - expect(result).toEqual(expectedResult); - }); -}); - \ No newline at end of file diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/buildspec.yml b/nodejs16.x/web/{{cookiecutter.project_name}}/buildspec.yml deleted file mode 100644 index 7c1dae85e..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/buildspec.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: 0.2 -phases: - install: - commands: - # Install all dependencies (including dependencies for running tests) - - npm install - pre_build: - commands: - # Discover and run unit tests in the '__tests__' directory - - npm run test - # Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda - - rm -rf ./__tests__ - # Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json) - - npm prune --production - build: - commands: - # Use AWS SAM to package the application by using AWS CloudFormation - - aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --output-template template-export.yml -artifacts: - type: zip - files: - - template-export.yml diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/env.json b/nodejs16.x/web/{{cookiecutter.project_name}}/env.json deleted file mode 100644 index c6073eb26..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/env.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "getAllItemsFunction": { - "SAMPLE_TABLE": "" - }, - "getByIdFunction": { - "SAMPLE_TABLE": "" - }, - "putItemFunction": { - "SAMPLE_TABLE": "" - } - } \ No newline at end of file diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/events/event-get-all-items.json b/nodejs16.x/web/{{cookiecutter.project_name}}/events/event-get-all-items.json deleted file mode 100644 index 3a0cb5f77..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/events/event-get-all-items.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "httpMethod": "GET" -} \ No newline at end of file diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/events/event-get-by-id.json b/nodejs16.x/web/{{cookiecutter.project_name}}/events/event-get-by-id.json deleted file mode 100644 index 63a64fb45..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/events/event-get-by-id.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "httpMethod": "GET", - "pathParameters": { - "id": "id1" - } -} \ No newline at end of file diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/events/event-post-item.json b/nodejs16.x/web/{{cookiecutter.project_name}}/events/event-post-item.json deleted file mode 100644 index 6367003e5..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/events/event-post-item.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "httpMethod": "POST", - "body": "{\"id\": \"id1\",\"name\": \"name1\"}" -} \ No newline at end of file diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/package.json b/nodejs16.x/web/{{cookiecutter.project_name}}/package.json deleted file mode 100644 index bbf417af9..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "delete-test-01", - "description": "delete-test-01-description", - "version": "0.0.1", - "private": true, - "dependencies": { - "aws-sdk": "^2.799.0" - }, - "devDependencies": { - "jest": "^26.6.3" - }, - "scripts": { - "test": "jest" - } -} - diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/get-all-items.js b/nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/get-all-items.js deleted file mode 100644 index e055e2d7c..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/get-all-items.js +++ /dev/null @@ -1,47 +0,0 @@ -// Create clients and set shared const values outside of the handler. - -// Get the DynamoDB table name from environment variables -const tableName = process.env.SAMPLE_TABLE; - -// Create a DocumentClient that represents the query to add an item -const dynamodb = require('aws-sdk/clients/dynamodb'); -const docClient = new dynamodb.DocumentClient(); - -/** - * A simple example includes a HTTP get method to get all items from a DynamoDB table. - */ -exports.getAllItemsHandler = async (event) => { - if (event.httpMethod !== 'GET') { - throw new Error(`getAllItems only accept GET method, you tried: ${event.httpMethod}`); - } - // All log statements are written to CloudWatch - console.info('received:', event); - - // get all items from the table (only first 1MB data, you can use `LastEvaluatedKey` to get the rest of data) - // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#scan-property - // https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html - - let response = {}; - - try { - const params = { - TableName : tableName - }; - const data = await docClient.scan(params).promise(); - const items = data.Items; - - response = { - statusCode: 200, - body: JSON.stringify(items) - }; - } catch (ResourceNotFoundException) { - response = { - statusCode: 404, - body: "Unable to call DynamoDB. Table resource not found." - }; - } - - // All log statements are written to CloudWatch - console.info(`response from: ${event.path} statusCode: ${response.statusCode} body: ${response.body}`); - return response; -} diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/get-by-id.js b/nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/get-by-id.js deleted file mode 100644 index 58568f9c0..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/get-by-id.js +++ /dev/null @@ -1,49 +0,0 @@ -// Create clients and set shared const values outside of the handler. - -// Get the DynamoDB table name from environment variables -const tableName = process.env.SAMPLE_TABLE; - -// Create a DocumentClient that represents the query to add an item -const dynamodb = require('aws-sdk/clients/dynamodb'); -const docClient = new dynamodb.DocumentClient(); - -/** - * A simple example includes a HTTP get method to get one item by id from a DynamoDB table. - */ -exports.getByIdHandler = async (event) => { - if (event.httpMethod !== 'GET') { - throw new Error(`getMethod only accept GET method, you tried: ${event.httpMethod}`); - } - // All log statements are written to CloudWatch - console.info('received:', event); - - // Get id from pathParameters from APIGateway because of `/{id}` at template.yaml - const id = event.pathParameters.id; - - // Get the item from the table - // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#get-property - let response = {}; - - try { - const params = { - TableName : tableName, - Key: { id: id }, - }; - const data = await docClient.get(params).promise(); - const item = data.Item; - - response = { - statusCode: 200, - body: JSON.stringify(item) - }; - } catch (ResourceNotFoundException) { - response = { - statusCode: 404, - body: "Unable to call DynamoDB. Table resource not found." - }; - } - - // All log statements are written to CloudWatch - console.info(`response from: ${event.path} statusCode: ${response.statusCode} body: ${response.body}`); - return response; -} diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/put-item.js b/nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/put-item.js deleted file mode 100644 index 82d7bbf23..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/src/handlers/put-item.js +++ /dev/null @@ -1,51 +0,0 @@ -// Create clients and set shared const values outside of the handler. - -// Create a DocumentClient that represents the query to add an item -const dynamodb = require('aws-sdk/clients/dynamodb'); -const docClient = new dynamodb.DocumentClient(); - -// Get the DynamoDB table name from environment variables -const tableName = process.env.SAMPLE_TABLE; - -/** - * A simple example includes a HTTP post method to add one item to a DynamoDB table. - */ -exports.putItemHandler = async (event) => { - if (event.httpMethod !== 'POST') { - throw new Error(`postMethod only accepts POST method, you tried: ${event.httpMethod} method.`); - } - // All log statements are written to CloudWatch - console.info('received:', event); - - // Get id and name from the body of the request - const body = JSON.parse(event.body); - const id = body.id; - const name = body.name; - - // Creates a new item, or replaces an old item with a new item - // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#put-property - let response = {}; - - try { - const params = { - TableName : tableName, - Item: { id : id, name: name } - }; - - const result = await docClient.put(params).promise(); - - response = { - statusCode: 200, - body: JSON.stringify(body) - }; - } catch (ResourceNotFoundException) { - response = { - statusCode: 404, - body: "Unable to call DynamoDB. Table resource not found." - }; - } - - // All log statements are written to CloudWatch - console.info(`response from: ${event.path} statusCode: ${response.statusCode} body: ${response.body}`); - return response; -}; diff --git a/nodejs16.x/web/{{cookiecutter.project_name}}/template.yaml b/nodejs16.x/web/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index 19120caf1..000000000 --- a/nodejs16.x/web/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,131 +0,0 @@ -# This is the SAM template that represents the architecture of your serverless application -# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html - -# The AWSTemplateFormatVersion identifies the capabilities of the template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html -AWSTemplateFormatVersion: 2010-09-09 -Description: >- - {{cookiecutter.project_name}} - -# Transform section specifies one or more macros that AWS CloudFormation uses to process your template -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html -Transform: -- AWS::Serverless-2016-10-31 - -# Resources declares the AWS resources that you want to include in the stack -# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html -Resources: - # Each Lambda function is defined by properties: - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - - # This is a Lambda function config associated with the source code: get-all-items.js - getAllItemsFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - MemorySize: 128 - Timeout: 100 - Description: A simple example includes a HTTP get method to get all items from a DynamoDB table. - Policies: - # Give Create/Read/Update/Delete Permissions to the SampleTable - - DynamoDBCrudPolicy: - TableName: !Ref SampleTable - Environment: - Variables: - # Make table name accessible as environment variable from function code during execution - SAMPLE_TABLE: !Ref SampleTable - Events: - Api: - Type: Api - Properties: - Path: / - Method: GET - # Each Lambda function is defined by properties: - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - - # This is a Lambda function config associated with the source code: get-by-id.js - getByIdFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/get-by-id.getByIdHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - MemorySize: 128 - Timeout: 100 - Description: A simple example includes a HTTP get method to get one item by id from a DynamoDB table. - Policies: - # Give Create/Read/Update/Delete Permissions to the SampleTable - - DynamoDBCrudPolicy: - TableName: !Ref SampleTable - Environment: - Variables: - # Make table name accessible as environment variable from function code during execution - SAMPLE_TABLE: !Ref SampleTable - Events: - Api: - Type: Api - Properties: - Path: /{id} - Method: GET - # Each Lambda function is defined by properties: - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - - # This is a Lambda function config associated with the source code: put-item.js - putItemFunction: - Type: AWS::Serverless::Function - Properties: - Handler: src/handlers/put-item.putItemHandler - Runtime: nodejs16.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - MemorySize: 128 - Timeout: 100 - Description: A simple example includes a HTTP post method to add one item to a DynamoDB table. - Policies: - # Give Create/Read/Update/Delete Permissions to the SampleTable - - DynamoDBCrudPolicy: - TableName: !Ref SampleTable - Environment: - Variables: - # Make table name accessible as environment variable from function code during execution - SAMPLE_TABLE: !Ref SampleTable - Events: - Api: - Type: Api - Properties: - Path: / - Method: POST - # Simple syntax to create a DynamoDB table with a single attribute primary key, more in - # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesssimpletable - - # DynamoDB table to store item: {id: <ID>, name: <NAME>} - SampleTable: - Type: AWS::Serverless::SimpleTable - Properties: - PrimaryKey: - Name: id - Type: String - ProvisionedThroughput: - ReadCapacityUnits: 2 - WriteCapacityUnits: 2 - -Outputs: - WebEndpoint: - Description: "API Gateway endpoint URL for Prod stage" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/" diff --git a/python3.10/web-conn/{{cookiecutter.project_name}}/README.md b/python3.10/web-conn/{{cookiecutter.project_name}}/README.md index 27577a064..2110c1164 100644 --- a/python3.10/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.10/web-conn/{{cookiecutter.project_name}}/README.md @@ -103,7 +103,7 @@ Resources: Type: AWS::Serverless::Function Properties: Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x + Runtime: nodejs20.x DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.11/web-conn/{{cookiecutter.project_name}}/README.md b/python3.11/web-conn/{{cookiecutter.project_name}}/README.md index 27577a064..2110c1164 100644 --- a/python3.11/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.11/web-conn/{{cookiecutter.project_name}}/README.md @@ -103,7 +103,7 @@ Resources: Type: AWS::Serverless::Function Properties: Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x + Runtime: nodejs20.x DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.12/web-conn/{{cookiecutter.project_name}}/README.md b/python3.12/web-conn/{{cookiecutter.project_name}}/README.md index 27577a064..2110c1164 100644 --- a/python3.12/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.12/web-conn/{{cookiecutter.project_name}}/README.md @@ -103,7 +103,7 @@ Resources: Type: AWS::Serverless::Function Properties: Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x + Runtime: nodejs20.x DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.13/web-conn/{{cookiecutter.project_name}}/README.md b/python3.13/web-conn/{{cookiecutter.project_name}}/README.md index 27577a064..2110c1164 100644 --- a/python3.13/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.13/web-conn/{{cookiecutter.project_name}}/README.md @@ -103,7 +103,7 @@ Resources: Type: AWS::Serverless::Function Properties: Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x + Runtime: nodejs20.x DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.8/web-conn/{{cookiecutter.project_name}}/README.md b/python3.8/web-conn/{{cookiecutter.project_name}}/README.md index 27577a064..2110c1164 100644 --- a/python3.8/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.8/web-conn/{{cookiecutter.project_name}}/README.md @@ -103,7 +103,7 @@ Resources: Type: AWS::Serverless::Function Properties: Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x + Runtime: nodejs20.x DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.9/web-conn/{{cookiecutter.project_name}}/README.md b/python3.9/web-conn/{{cookiecutter.project_name}}/README.md index 27577a064..2110c1164 100644 --- a/python3.9/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.9/web-conn/{{cookiecutter.project_name}}/README.md @@ -103,7 +103,7 @@ Resources: Type: AWS::Serverless::Function Properties: Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs16.x + Runtime: nodejs20.x DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/tests/integration/build_invoke/node/test_node_16.py b/tests/integration/build_invoke/node/test_node_16.py deleted file mode 100644 index d4871e818..000000000 --- a/tests/integration/build_invoke/node/test_node_16.py +++ /dev/null @@ -1,62 +0,0 @@ -from tests.integration.build_invoke.build_invoke_base import BuildInvokeBase - -""" -For each template, it will test the following sam commands: -1. sam init -2. sam build --use-container (if self.use_container is False, --use-container will be omitted) -3. (if there are event jsons), for each event json, check `sam local invoke` response is a valid json - -Nodejs 16 is now deprecated and will fail the linter check. Skip running `sam validate --lint` -""" - -class BuildInvoke_nodejs16_x_cookiecutter_aws_sam_hello_nodejs(BuildInvokeBase.SimpleHelloWorldBuildInvokeBase): - directory = "nodejs16.x/hello" - should_test_lint = False - - -class BuildInvoke_nodejs16_x_cookiecutter_aws_sam_step_functions_sample_app(BuildInvokeBase.BuildInvokeBase): - directory = "nodejs16.x/step-func" - should_test_lint = False - - -class BuildInvoke_nodejs16_x_cookiecutter_quick_start_from_scratch(BuildInvokeBase.BuildInvokeBase): - directory = "nodejs16.x/scratch" - should_test_lint = False - - -class BuildInvoke_nodejs16_x_cookiecutter_quick_start_cloudwatch_events(BuildInvokeBase.BuildInvokeBase): - directory = "nodejs16.x/cw-event" - should_test_lint = False - - -class BuildInvoke_nodejs16_x_cookiecutter_quick_start_s3(BuildInvokeBase.BuildInvokeBase): - directory = "nodejs16.x/s3" - should_test_lint = False - - # if we want to check response json, we need to setup bucket for testing - - -class BuildInvoke_nodejs16_x_cookiecutter_quick_start_sns(BuildInvokeBase.BuildInvokeBase): - directory = "nodejs16.x/sns" - should_test_lint = False - - -class BuildInvoke_nodejs16_x_cookiecutter_quick_start_sqs(BuildInvokeBase.BuildInvokeBase): - directory = "nodejs16.x/sqs" - should_test_lint = False - - -class BuildInvoke_nodejs16_x_cookiecutter_quick_start_response_streaming(BuildInvokeBase.BuildInvokeBase): - directory = "nodejs16.x/response-streaming" - should_test_lint = False - - -class BuildInvoke_nodejs16_x_cookiecutter_quick_start_web(BuildInvokeBase.QuickStartWebBuildInvokeBase): - directory = "nodejs16.x/web" - should_test_lint = False - -class BuildInvoke_image_nodejs16_x_cookiecutter_aws_sam_hello_nodejs_lambda_image( - BuildInvokeBase.SimpleHelloWorldBuildInvokeBase -): - directory = "nodejs16.x/hello-img" - should_test_lint = False diff --git a/tests/integration/unit_test/test_unit_test_nodejs16_x.py b/tests/integration/unit_test/test_unit_test_nodejs16_x.py deleted file mode 100644 index f5890290a..000000000 --- a/tests/integration/unit_test/test_unit_test_nodejs16_x.py +++ /dev/null @@ -1,71 +0,0 @@ -from tests.integration.unit_test.unit_test_base import UnitTestBase - -""" -Nodejs 16 is now deprecated and will fail the linter check. Skip running `sam validate --lint` -""" - -class UnitTest_nodejs16_x_cookiecutter_aws_sam_hello_nodejs(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/hello" - code_directories = ["hello-world"] - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_aws_sam_step_functions_sample_app(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/step-func" - code_directories = [ - "functions/stock-buyer", - "functions/stock-checker", - "functions/stock-seller", - ] - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_quick_start_from_scratch(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/scratch" - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_quick_start_cloudwatch_events(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/cw-event" - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_quick_start_response_streaming(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/response-streaming" - code_directories = ["src"] - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_quick_start_s3(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/s3" - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_quick_start_sns(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/sns" - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_quick_start_sqs(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/sqs" - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_quick_start_web(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/web" - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_aws_sam_quick_start_web_with_connectors(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/web-conn" - should_test_lint = False - - -class UnitTest_nodejs16_x_cookiecutter_aws_sam_step_functions_with_connectors(UnitTestBase.NodejsUnitTestBase): - directory = "nodejs16.x/step-func-conn" - code_directories = [ - "functions/stock-buyer", - "functions/stock-checker", - "functions/stock-seller", - ] - should_test_lint = False From 6f1691c993efb9ad63379e18c6f920e20e20b0ce Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:40:04 -0800 Subject: [PATCH 2/2] fix python readme files --- python3.10/web-conn/{{cookiecutter.project_name}}/README.md | 4 ++-- python3.11/web-conn/{{cookiecutter.project_name}}/README.md | 4 ++-- python3.12/web-conn/{{cookiecutter.project_name}}/README.md | 4 ++-- python3.13/web-conn/{{cookiecutter.project_name}}/README.md | 4 ++-- python3.8/web-conn/{{cookiecutter.project_name}}/README.md | 4 ++-- python3.9/web-conn/{{cookiecutter.project_name}}/README.md | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/python3.10/web-conn/{{cookiecutter.project_name}}/README.md b/python3.10/web-conn/{{cookiecutter.project_name}}/README.md index 2110c1164..f80cbc422 100644 --- a/python3.10/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.10/web-conn/{{cookiecutter.project_name}}/README.md @@ -102,8 +102,8 @@ Resources: getAllItemsFunction: Type: AWS::Serverless::Function Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs20.x + Handler: src/handlers/get_all_items.getAllItemsHandler + Runtime: python3.10 DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.11/web-conn/{{cookiecutter.project_name}}/README.md b/python3.11/web-conn/{{cookiecutter.project_name}}/README.md index 2110c1164..b2534288b 100644 --- a/python3.11/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.11/web-conn/{{cookiecutter.project_name}}/README.md @@ -102,8 +102,8 @@ Resources: getAllItemsFunction: Type: AWS::Serverless::Function Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs20.x + Handler: src/handlers/get_all_items.getAllItemsHandler + Runtime: python3.11 DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.12/web-conn/{{cookiecutter.project_name}}/README.md b/python3.12/web-conn/{{cookiecutter.project_name}}/README.md index 2110c1164..ddb0c7883 100644 --- a/python3.12/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.12/web-conn/{{cookiecutter.project_name}}/README.md @@ -102,8 +102,8 @@ Resources: getAllItemsFunction: Type: AWS::Serverless::Function Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs20.x + Handler: src/handlers/get_all_items.getAllItemsHandler + Runtime: python3.12 DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.13/web-conn/{{cookiecutter.project_name}}/README.md b/python3.13/web-conn/{{cookiecutter.project_name}}/README.md index 2110c1164..1d3397b66 100644 --- a/python3.13/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.13/web-conn/{{cookiecutter.project_name}}/README.md @@ -102,8 +102,8 @@ Resources: getAllItemsFunction: Type: AWS::Serverless::Function Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs20.x + Handler: src/handlers/get_all_items.getAllItemsHandler + Runtime: python3.13 DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.8/web-conn/{{cookiecutter.project_name}}/README.md b/python3.8/web-conn/{{cookiecutter.project_name}}/README.md index 2110c1164..8b50d64e2 100644 --- a/python3.8/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.8/web-conn/{{cookiecutter.project_name}}/README.md @@ -102,8 +102,8 @@ Resources: getAllItemsFunction: Type: AWS::Serverless::Function Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs20.x + Handler: src/handlers/get_all_items.getAllItemsHandler + Runtime: python3.8 DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn diff --git a/python3.9/web-conn/{{cookiecutter.project_name}}/README.md b/python3.9/web-conn/{{cookiecutter.project_name}}/README.md index 2110c1164..26404312e 100644 --- a/python3.9/web-conn/{{cookiecutter.project_name}}/README.md +++ b/python3.9/web-conn/{{cookiecutter.project_name}}/README.md @@ -102,8 +102,8 @@ Resources: getAllItemsFunction: Type: AWS::Serverless::Function Properties: - Handler: src/handlers/get-all-items.getAllItemsHandler - Runtime: nodejs20.x + Handler: src/handlers/get_all_items.getAllItemsHandler + Runtime: python3.9 DeadLetterQueue: Type: SQS TargetArn: !GetAtt MyQueue.Arn