From c6c39d04c6b5561d71e6995b074cd4a4778d012b Mon Sep 17 00:00:00 2001 From: Edward Foyle Date: Wed, 29 Nov 2023 16:36:17 -0800 Subject: [PATCH] `defineFunction` initial implementation (#742) * build working * update package lock * updating test cases * update snapshots * update api extract * add changeset * fix api * fix auto-rename mishap * update e2e test case * add additional check to e2e suite * lint fixes * update snapshots * trying this * updating assertion * update snapshots * addressing PR comments * update snapshots * update api extract * update changeset * fix lint * Im dumb * still dumb * remove unused code * hopefully last fix * update snapshots * json parse lambda output --- .changeset/few-carpets-search.md | 5 + .changeset/mighty-rockets-shake.md | 7 + package-lock.json | 506 +++++++++++++++++- packages/backend-function/API.md | 31 +- packages/backend-function/package.json | 4 +- packages/backend-function/src/factory.test.ts | 95 +++- packages/backend-function/src/factory.ts | 186 +++---- .../src/test-assets/default-lambda/handler.ts | 6 + .../test-assets/default-lambda/resource.ts | 7 + .../lambda-with-dependencies/handler.ts | 6 + .../lambda-with-dependencies/resource.ts | 3 + .../response_generator.ts | 6 + .../test-assets/test-lambda/mock.txt | 2 - packages/backend-function/tsconfig.json | 1 - packages/backend/API.md | 6 +- packages/backend/src/index.ts | 2 +- ...BranchName-branch-7d6f6c854a.template.json | 2 +- ...d6f6c854adataE67321C2.nested.template.json | 2 +- packages/function-construct/.npmignore | 14 - packages/function-construct/API.md | 28 - packages/function-construct/CHANGELOG.md | 87 --- .../function-construct/api-extractor.json | 3 - packages/function-construct/package.json | 27 - .../function-construct/src/construct.test.ts | 74 --- packages/function-construct/src/construct.ts | 45 -- packages/function-construct/src/index.ts | 1 - .../test-assets/test-lambda/mock.txt | 2 - packages/function-construct/tsconfig.json | 5 - packages/function-construct/typedoc.json | 3 - packages/integration-tests/package.json | 6 +- .../src/find_deployed_resource.ts | 61 +++ .../src/test-e2e/deployment.test.ts | 6 +- .../data_storage_auth_with_triggers.ts | 51 +- .../test-project-setup/test_project_base.ts | 6 +- .../test_project_creator.ts | 11 +- ...BranchName-branch-7d6f6c854a.template.json | 2 +- ...d6f6c854adataE67321C2.nested.template.json | 2 +- .../amplify/data/echo/handler.cjs | 6 + .../amplify/data/echo/mock.txt | 2 - .../amplify/data/resource.cjs | 6 +- .../amplify/func-src/handler.cjs | 6 + .../amplify/func-src/mock.txt | 2 - .../amplify/function.cjs | 7 +- ...BranchName-branch-7d6f6c854a.template.json | 18 +- ...d6f6c854aauth473E022C.nested.template.json | 6 +- ...d6f6c854adataE67321C2.nested.template.json | 14 +- ...irectiveStack93F75775.nested.template.json | 16 +- ...c854afunctionDE2842E0.nested.template.json | 43 +- .../update-1/data/resource.ts | 2 +- .../amplify/data/echo/handler.js | 6 + .../amplify/data/echo/mock.txt | 2 - .../amplify/data/resource.js | 6 +- .../amplify/func-src/handler.js | 6 + .../amplify/func-src/mock.txt | 2 - .../amplify/function.js | 7 +- ...BranchName-branch-7d6f6c854a.template.json | 18 +- ...d6f6c854aauth473E022C.nested.template.json | 6 +- ...d6f6c854adataE67321C2.nested.template.json | 14 +- ...irectiveStack93F75775.nested.template.json | 16 +- ...c854afunctionDE2842E0.nested.template.json | 43 +- .../update-1/data/resource.ts | 2 +- .../amplify/data/echo/handler.ts | 6 + .../amplify/data/echo/mock.txt | 2 - .../amplify/data/resource.ts | 11 +- .../amplify/func-src/handler.ts | 6 + .../amplify/func-src/mock.txt | 2 - .../amplify/func-src/response_generator.ts | 14 + .../amplify/function.ts | 8 +- ...BranchName-branch-7d6f6c854a.template.json | 14 +- ...d6f6c854aauth473E022C.nested.template.json | 6 +- ...d6f6c854adataE67321C2.nested.template.json | 10 +- ...irectiveStack93F75775.nested.template.json | 8 +- ...c854afunctionDE2842E0.nested.template.json | 43 +- .../update-1/data/resource.ts | 11 +- .../update-1/function.ts | 7 +- .../amplify/data/api-auth/mock.txt | 2 - .../amplify/data/lambda_authorizer.ts | 6 + .../amplify/data/resource.ts | 8 +- ...BranchName-branch-7d6f6c854a.template.json | 8 +- ...d6f6c854adataE67321C2.nested.template.json | 6 +- ...c854afunctionDE2842E0.nested.template.json | 26 +- ...BranchName-branch-7d6f6c854a.template.json | 2 +- ...d6f6c854adataE67321C2.nested.template.json | 2 +- packages/plugin-types/API.md | 4 +- .../plugin-types/src/function_resources.ts | 4 +- 85 files changed, 1112 insertions(+), 671 deletions(-) create mode 100644 .changeset/few-carpets-search.md create mode 100644 .changeset/mighty-rockets-shake.md create mode 100644 packages/backend-function/src/test-assets/default-lambda/handler.ts create mode 100644 packages/backend-function/src/test-assets/default-lambda/resource.ts create mode 100644 packages/backend-function/src/test-assets/lambda-with-dependencies/handler.ts create mode 100644 packages/backend-function/src/test-assets/lambda-with-dependencies/resource.ts create mode 100644 packages/backend-function/src/test-assets/lambda-with-dependencies/response_generator.ts delete mode 100644 packages/backend-function/test-assets/test-lambda/mock.txt delete mode 100644 packages/function-construct/.npmignore delete mode 100644 packages/function-construct/API.md delete mode 100644 packages/function-construct/CHANGELOG.md delete mode 100644 packages/function-construct/api-extractor.json delete mode 100644 packages/function-construct/package.json delete mode 100644 packages/function-construct/src/construct.test.ts delete mode 100644 packages/function-construct/src/construct.ts delete mode 100644 packages/function-construct/src/index.ts delete mode 100644 packages/function-construct/test-assets/test-lambda/mock.txt delete mode 100644 packages/function-construct/tsconfig.json delete mode 100644 packages/function-construct/typedoc.json create mode 100644 packages/integration-tests/src/find_deployed_resource.ts create mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/echo/handler.cjs delete mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/echo/mock.txt create mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/func-src/handler.cjs delete mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/func-src/mock.txt create mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/echo/handler.js delete mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/echo/mock.txt create mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/func-src/handler.js delete mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/func-src/mock.txt create mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/echo/handler.ts delete mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/echo/mock.txt create mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/handler.ts delete mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/mock.txt create mode 100644 packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/response_generator.ts delete mode 100644 packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/api-auth/mock.txt create mode 100644 packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/lambda_authorizer.ts diff --git a/.changeset/few-carpets-search.md b/.changeset/few-carpets-search.md new file mode 100644 index 0000000000..20381169c7 --- /dev/null +++ b/.changeset/few-carpets-search.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/backend-function': minor +--- + +Initial implementation of new 'defineFunction' entry point diff --git a/.changeset/mighty-rockets-shake.md b/.changeset/mighty-rockets-shake.md new file mode 100644 index 0000000000..09bfce3e82 --- /dev/null +++ b/.changeset/mighty-rockets-shake.md @@ -0,0 +1,7 @@ +--- +'create-amplify': patch +'@aws-amplify/plugin-types': minor +'@aws-amplify/backend': minor +--- + +Expose new `defineFunction` interface diff --git a/package-lock.json b/package-lock.json index 4beb73b7a8..f565fad4d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1084,10 +1084,6 @@ "resolved": "packages/form-generator", "link": true }, - "node_modules/@aws-amplify/function-construct-alpha": { - "resolved": "packages/function-construct", - "link": true - }, "node_modules/@aws-amplify/graphql-api-construct": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/@aws-amplify/graphql-api-construct/-/graphql-api-construct-1.4.2.tgz", @@ -2907,6 +2903,469 @@ "node": ">=14.0.0" } }, + "node_modules/@aws-sdk/client-lambda": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-lambda/-/client-lambda-3.460.0.tgz", + "integrity": "sha512-GxLIzgLHSUqWXRbTOoSt7d7GG6RTkAT56yuBNDqT2JZmbYn6vSrpoEAEyVninKHx00vfKgXV2M4aOc1koT2YeQ==", + "dev": true, + "dependencies": { + "@aws-crypto/sha256-browser": "3.0.0", + "@aws-crypto/sha256-js": "3.0.0", + "@aws-sdk/client-sts": "3.460.0", + "@aws-sdk/core": "3.451.0", + "@aws-sdk/credential-provider-node": "3.460.0", + "@aws-sdk/middleware-host-header": "3.460.0", + "@aws-sdk/middleware-logger": "3.460.0", + "@aws-sdk/middleware-recursion-detection": "3.460.0", + "@aws-sdk/middleware-signing": "3.460.0", + "@aws-sdk/middleware-user-agent": "3.460.0", + "@aws-sdk/region-config-resolver": "3.451.0", + "@aws-sdk/types": "3.460.0", + "@aws-sdk/util-endpoints": "3.460.0", + "@aws-sdk/util-user-agent-browser": "3.460.0", + "@aws-sdk/util-user-agent-node": "3.460.0", + "@smithy/config-resolver": "^2.0.18", + "@smithy/eventstream-serde-browser": "^2.0.13", + "@smithy/eventstream-serde-config-resolver": "^2.0.13", + "@smithy/eventstream-serde-node": "^2.0.13", + "@smithy/fetch-http-handler": "^2.2.6", + "@smithy/hash-node": "^2.0.15", + "@smithy/invalid-dependency": "^2.0.13", + "@smithy/middleware-content-length": "^2.0.15", + "@smithy/middleware-endpoint": "^2.2.0", + "@smithy/middleware-retry": "^2.0.20", + "@smithy/middleware-serde": "^2.0.13", + "@smithy/middleware-stack": "^2.0.7", + "@smithy/node-config-provider": "^2.1.5", + "@smithy/node-http-handler": "^2.1.9", + "@smithy/protocol-http": "^3.0.9", + "@smithy/smithy-client": "^2.1.15", + "@smithy/types": "^2.5.0", + "@smithy/url-parser": "^2.0.13", + "@smithy/util-base64": "^2.0.1", + "@smithy/util-body-length-browser": "^2.0.0", + "@smithy/util-body-length-node": "^2.1.0", + "@smithy/util-defaults-mode-browser": "^2.0.19", + "@smithy/util-defaults-mode-node": "^2.0.25", + "@smithy/util-endpoints": "^1.0.4", + "@smithy/util-retry": "^2.0.6", + "@smithy/util-stream": "^2.0.20", + "@smithy/util-utf8": "^2.0.2", + "@smithy/util-waiter": "^2.0.13", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/client-sso": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso/-/client-sso-3.460.0.tgz", + "integrity": "sha512-p5D9C8LKJs5yoBn5cCs2Wqzrp5YP5BYcP774bhGMFEu/LCIUyWzudwN3+/AObSiq8R8SSvBY2zQD4h+k3NjgTQ==", + "dev": true, + "dependencies": { + "@aws-crypto/sha256-browser": "3.0.0", + "@aws-crypto/sha256-js": "3.0.0", + "@aws-sdk/core": "3.451.0", + "@aws-sdk/middleware-host-header": "3.460.0", + "@aws-sdk/middleware-logger": "3.460.0", + "@aws-sdk/middleware-recursion-detection": "3.460.0", + "@aws-sdk/middleware-user-agent": "3.460.0", + "@aws-sdk/region-config-resolver": "3.451.0", + "@aws-sdk/types": "3.460.0", + "@aws-sdk/util-endpoints": "3.460.0", + "@aws-sdk/util-user-agent-browser": "3.460.0", + "@aws-sdk/util-user-agent-node": "3.460.0", + "@smithy/config-resolver": "^2.0.18", + "@smithy/fetch-http-handler": "^2.2.6", + "@smithy/hash-node": "^2.0.15", + "@smithy/invalid-dependency": "^2.0.13", + "@smithy/middleware-content-length": "^2.0.15", + "@smithy/middleware-endpoint": "^2.2.0", + "@smithy/middleware-retry": "^2.0.20", + "@smithy/middleware-serde": "^2.0.13", + "@smithy/middleware-stack": "^2.0.7", + "@smithy/node-config-provider": "^2.1.5", + "@smithy/node-http-handler": "^2.1.9", + "@smithy/protocol-http": "^3.0.9", + "@smithy/smithy-client": "^2.1.15", + "@smithy/types": "^2.5.0", + "@smithy/url-parser": "^2.0.13", + "@smithy/util-base64": "^2.0.1", + "@smithy/util-body-length-browser": "^2.0.0", + "@smithy/util-body-length-node": "^2.1.0", + "@smithy/util-defaults-mode-browser": "^2.0.19", + "@smithy/util-defaults-mode-node": "^2.0.25", + "@smithy/util-endpoints": "^1.0.4", + "@smithy/util-retry": "^2.0.6", + "@smithy/util-utf8": "^2.0.2", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/client-sts": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-sts/-/client-sts-3.460.0.tgz", + "integrity": "sha512-Z4h9hZJG5RB9iwhyXlkcnJqCP25+rgIrT8UDryItJfWyK+Pberk1Zft7XwEiyDGXoc48BJvtf7SbOwx3cutgFw==", + "dev": true, + "dependencies": { + "@aws-crypto/sha256-browser": "3.0.0", + "@aws-crypto/sha256-js": "3.0.0", + "@aws-sdk/core": "3.451.0", + "@aws-sdk/credential-provider-node": "3.460.0", + "@aws-sdk/middleware-host-header": "3.460.0", + "@aws-sdk/middleware-logger": "3.460.0", + "@aws-sdk/middleware-recursion-detection": "3.460.0", + "@aws-sdk/middleware-sdk-sts": "3.460.0", + "@aws-sdk/middleware-signing": "3.460.0", + "@aws-sdk/middleware-user-agent": "3.460.0", + "@aws-sdk/region-config-resolver": "3.451.0", + "@aws-sdk/types": "3.460.0", + "@aws-sdk/util-endpoints": "3.460.0", + "@aws-sdk/util-user-agent-browser": "3.460.0", + "@aws-sdk/util-user-agent-node": "3.460.0", + "@smithy/config-resolver": "^2.0.18", + "@smithy/fetch-http-handler": "^2.2.6", + "@smithy/hash-node": "^2.0.15", + "@smithy/invalid-dependency": "^2.0.13", + "@smithy/middleware-content-length": "^2.0.15", + "@smithy/middleware-endpoint": "^2.2.0", + "@smithy/middleware-retry": "^2.0.20", + "@smithy/middleware-serde": "^2.0.13", + "@smithy/middleware-stack": "^2.0.7", + "@smithy/node-config-provider": "^2.1.5", + "@smithy/node-http-handler": "^2.1.9", + "@smithy/protocol-http": "^3.0.9", + "@smithy/smithy-client": "^2.1.15", + "@smithy/types": "^2.5.0", + "@smithy/url-parser": "^2.0.13", + "@smithy/util-base64": "^2.0.1", + "@smithy/util-body-length-browser": "^2.0.0", + "@smithy/util-body-length-node": "^2.1.0", + "@smithy/util-defaults-mode-browser": "^2.0.19", + "@smithy/util-defaults-mode-node": "^2.0.25", + "@smithy/util-endpoints": "^1.0.4", + "@smithy/util-retry": "^2.0.6", + "@smithy/util-utf8": "^2.0.2", + "fast-xml-parser": "4.2.5", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/credential-provider-env": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.460.0.tgz", + "integrity": "sha512-WWdaRJFuYRc2Ue9NKDy2NIf8pQRNx/QRVmrsk6EkIID8uWlQIOePk3SWTVV0TZIyPrbfSEaSnJRZoShphJ6PAg==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/property-provider": "^2.0.0", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/credential-provider-ini": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.460.0.tgz", + "integrity": "sha512-1IEUmyaWzt2M3mONO8QyZtPy0f9ccaEjCo48ZQLgptWxUI+Ohga9gPK0mqu1kTJOjv4JJGACYHzLwEnnpltGlA==", + "dev": true, + "dependencies": { + "@aws-sdk/credential-provider-env": "3.460.0", + "@aws-sdk/credential-provider-process": "3.460.0", + "@aws-sdk/credential-provider-sso": "3.460.0", + "@aws-sdk/credential-provider-web-identity": "3.460.0", + "@aws-sdk/types": "3.460.0", + "@smithy/credential-provider-imds": "^2.0.0", + "@smithy/property-provider": "^2.0.0", + "@smithy/shared-ini-file-loader": "^2.0.6", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/credential-provider-node": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.460.0.tgz", + "integrity": "sha512-PbPo92WIgNlF6V4eWKehYGYjTqf0gU9vr09LeQUc3bTm1DJhJw1j+HU/3PfQ8LwTkBQePO7MbJ5A2n6ckMwfMg==", + "dev": true, + "dependencies": { + "@aws-sdk/credential-provider-env": "3.460.0", + "@aws-sdk/credential-provider-ini": "3.460.0", + "@aws-sdk/credential-provider-process": "3.460.0", + "@aws-sdk/credential-provider-sso": "3.460.0", + "@aws-sdk/credential-provider-web-identity": "3.460.0", + "@aws-sdk/types": "3.460.0", + "@smithy/credential-provider-imds": "^2.0.0", + "@smithy/property-provider": "^2.0.0", + "@smithy/shared-ini-file-loader": "^2.0.6", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/credential-provider-process": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.460.0.tgz", + "integrity": "sha512-ng+0FMc4EaxLAwdttCwf2nzNf4AgcqAHZ8pKXUf8qF/KVkoyTt3UZKW7P2FJI01zxwP+V4yAwVt95PBUKGn4YQ==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/property-provider": "^2.0.0", + "@smithy/shared-ini-file-loader": "^2.0.6", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/credential-provider-sso": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.460.0.tgz", + "integrity": "sha512-KnrQieOw17+aHEzE3SwfxjeSQ5ZTe2HeAzxkaZF++GxhNul/PkVnLzjGpIuB9bn71T9a2oNfG3peDUA+m2l2kw==", + "dev": true, + "dependencies": { + "@aws-sdk/client-sso": "3.460.0", + "@aws-sdk/token-providers": "3.460.0", + "@aws-sdk/types": "3.460.0", + "@smithy/property-provider": "^2.0.0", + "@smithy/shared-ini-file-loader": "^2.0.6", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/credential-provider-web-identity": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.460.0.tgz", + "integrity": "sha512-7OeaZgC3HmJZGE0I0ZiKInUMF2LyA0IZiW85AYFnAZzAIfv1cXk/1UnDAoFIQhOZfnUBXivStagz892s480ryw==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/property-provider": "^2.0.0", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/middleware-host-header": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-host-header/-/middleware-host-header-3.460.0.tgz", + "integrity": "sha512-qBeDyuJkEuHe87Xk6unvFO9Zg5j6zM8bQOOZITocTLfu9JN0u5V4GQ/yopvpv+nQHmC/MGr0G7p+kIXMrg/Q2A==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/protocol-http": "^3.0.9", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/middleware-logger": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-logger/-/middleware-logger-3.460.0.tgz", + "integrity": "sha512-w2AJ6HOJ+Ggx9+VDKuWBHk5S0ZxYEo2EY2IFh0qtCQ1RDix/ur1QEzOOL5vNjHlZKPv/dseIwhgsTCac8UHXbQ==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/middleware-recursion-detection": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.460.0.tgz", + "integrity": "sha512-wmzm1/2NzpcCVCAsGqqiTBK+xNyLmQwTOq63rcW6eeq6gYOO0cyTZROOkVRrrsKWPBigrSFFHvDrEvonOMtKAg==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/protocol-http": "^3.0.9", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/middleware-sdk-sts": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-sdk-sts/-/middleware-sdk-sts-3.460.0.tgz", + "integrity": "sha512-eAaKBULwvIEToKweJtZ+gLrDPVwdi/XYjiJMJFBVDFk1n6kfHeS6BlNVrw713YrThpPiWfKNz8U3TvWtvD2Wpg==", + "dev": true, + "dependencies": { + "@aws-sdk/middleware-signing": "3.460.0", + "@aws-sdk/types": "3.460.0", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/middleware-signing": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-signing/-/middleware-signing-3.460.0.tgz", + "integrity": "sha512-f7dPf0TdyGMMlMoaGLV85nCfcGZOMIaNm+nR0x21H4SJyn1vCNSLMD6Nksav26hAdI3zreBtI2enudj8YYl2XA==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/property-provider": "^2.0.0", + "@smithy/protocol-http": "^3.0.9", + "@smithy/signature-v4": "^2.0.0", + "@smithy/types": "^2.5.0", + "@smithy/util-middleware": "^2.0.6", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/middleware-user-agent": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.460.0.tgz", + "integrity": "sha512-0gBSOCr+RtwRUCSRLn9H3RVnj9ercvk/QKTHIr33CgfEdyZtIGpHWUSs6uqiQydPTRzjCm5SfUa6ESGhRVMM6A==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@aws-sdk/util-endpoints": "3.460.0", + "@smithy/protocol-http": "^3.0.9", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/token-providers": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.460.0.tgz", + "integrity": "sha512-EvSIPMI1gXk3gEkdtbZCW+p3Bjmt2gOR1m7ibQD7qLj4l0dKXhp4URgTqB1ExH3S4qUq0M/XSGKbGLZpvunHNg==", + "dev": true, + "dependencies": { + "@aws-crypto/sha256-browser": "3.0.0", + "@aws-crypto/sha256-js": "3.0.0", + "@aws-sdk/middleware-host-header": "3.460.0", + "@aws-sdk/middleware-logger": "3.460.0", + "@aws-sdk/middleware-recursion-detection": "3.460.0", + "@aws-sdk/middleware-user-agent": "3.460.0", + "@aws-sdk/region-config-resolver": "3.451.0", + "@aws-sdk/types": "3.460.0", + "@aws-sdk/util-endpoints": "3.460.0", + "@aws-sdk/util-user-agent-browser": "3.460.0", + "@aws-sdk/util-user-agent-node": "3.460.0", + "@smithy/config-resolver": "^2.0.18", + "@smithy/fetch-http-handler": "^2.2.6", + "@smithy/hash-node": "^2.0.15", + "@smithy/invalid-dependency": "^2.0.13", + "@smithy/middleware-content-length": "^2.0.15", + "@smithy/middleware-endpoint": "^2.2.0", + "@smithy/middleware-retry": "^2.0.20", + "@smithy/middleware-serde": "^2.0.13", + "@smithy/middleware-stack": "^2.0.7", + "@smithy/node-config-provider": "^2.1.5", + "@smithy/node-http-handler": "^2.1.9", + "@smithy/property-provider": "^2.0.0", + "@smithy/protocol-http": "^3.0.9", + "@smithy/shared-ini-file-loader": "^2.0.6", + "@smithy/smithy-client": "^2.1.15", + "@smithy/types": "^2.5.0", + "@smithy/url-parser": "^2.0.13", + "@smithy/util-base64": "^2.0.1", + "@smithy/util-body-length-browser": "^2.0.0", + "@smithy/util-body-length-node": "^2.1.0", + "@smithy/util-defaults-mode-browser": "^2.0.19", + "@smithy/util-defaults-mode-node": "^2.0.25", + "@smithy/util-endpoints": "^1.0.4", + "@smithy/util-retry": "^2.0.6", + "@smithy/util-utf8": "^2.0.2", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/types": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.460.0.tgz", + "integrity": "sha512-MyZSWS/FV8Bnux5eD9en7KLgVxevlVrGNEP3X2D7fpnUlLhl0a7k8+OpSI2ozEQB8hIU2DLc/XXTKRerHSefxQ==", + "dev": true, + "dependencies": { + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/util-endpoints": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-endpoints/-/util-endpoints-3.460.0.tgz", + "integrity": "sha512-myH6kM5WP4IWULHDHMYf2Q+BCYVGlzqJgiBmO10kQEtJSeAGZZ49eoFFYgKW8ZAYB5VnJ+XhXVB1TRA+vR4l5A==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/util-endpoints": "^1.0.4", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/util-user-agent-browser": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.460.0.tgz", + "integrity": "sha512-FRCzW+TyjKnvxsargPVrjayBfp/rvObYHZyZ2OSqrVw8lkkPCb4e/WZOeIiXZuhdhhoah7wMuo6zGwtFF3bYKg==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/types": "^2.5.0", + "bowser": "^2.11.0", + "tslib": "^2.5.0" + } + }, + "node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/util-user-agent-node": { + "version": "3.460.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.460.0.tgz", + "integrity": "sha512-+kSoR9ABGpJ5Xc7v0VwpgTQbgyI4zuezC8K4pmKAGZsSsVWg4yxptoy2bDqoFL7qfRlWviMVTkQRMvR4D44WxA==", + "dev": true, + "dependencies": { + "@aws-sdk/types": "3.460.0", + "@smithy/node-config-provider": "^2.1.5", + "@smithy/types": "^2.5.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "aws-crt": ">=1.0.0" + }, + "peerDependenciesMeta": { + "aws-crt": { + "optional": true + } + } + }, "node_modules/@aws-sdk/client-s3": { "version": "3.454.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-s3/-/client-s3-3.454.0.tgz", @@ -20095,19 +20554,32 @@ "license": "Apache-2.0", "dependencies": { "@aws-amplify/backend-output-storage": "0.2.6", - "@aws-amplify/function-construct-alpha": "^0.2.1", "@aws-amplify/plugin-types": "^0.4.2", "execa": "^7.1.1" }, "devDependencies": { "@aws-amplify/backend-platform-test-stubs": "^0.3.1", - "@aws-amplify/platform-core": "^0.3.1" + "@aws-amplify/platform-core": "^0.3.1", + "uuid": "^9.0.1" }, "peerDependencies": { "aws-cdk-lib": "^2.110.1", "constructs": "^10.0.0" } }, + "packages/backend-function/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "packages/backend-output-schemas": { "name": "@aws-amplify/backend-output-schemas", "version": "0.4.0", @@ -20522,10 +20994,11 @@ }, "packages/function-construct": { "name": "@aws-amplify/function-construct-alpha", - "version": "0.2.1", + "version": "0.2.0", + "extraneous": true, "license": "Apache-2.0", "dependencies": { - "@aws-amplify/backend-output-storage": "^0.2.6" + "@aws-amplify/backend-output-storage": "^0.2.0" }, "peerDependencies": { "aws-cdk-lib": "^2.110.1", @@ -20546,9 +21019,11 @@ "@aws-amplify/platform-core": "^0.3.1", "@aws-sdk/client-amplify": "^3.440.0", "@aws-sdk/client-cloudformation": "^3.421.0", + "@aws-sdk/client-lambda": "^3.460.0", "execa": "^8.0.1", "fs-extra": "^11.1.1", - "glob": "^10.2.7" + "glob": "^10.2.7", + "uuid": "^9.0.1" } }, "packages/integration-tests/node_modules/execa": { @@ -20603,6 +21078,19 @@ "url": "https://github.com/sponsors/isaacs" } }, + "packages/integration-tests/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "packages/model-generator": { "name": "@aws-amplify/model-generator", "version": "0.2.3", diff --git a/packages/backend-function/API.md b/packages/backend-function/API.md index 4bb4a858a8..fb15232219 100644 --- a/packages/backend-function/API.md +++ b/packages/backend-function/API.md @@ -4,37 +4,20 @@ ```ts -import { AmplifyFunctionProps } from '@aws-amplify/function-construct-alpha'; -import { AmplifyLambdaFunction } from '@aws-amplify/function-construct-alpha'; +import { Construct } from 'constructs'; import { ConstructFactory } from '@aws-amplify/plugin-types'; -import { ConstructFactoryGetInstanceProps } from '@aws-amplify/plugin-types'; +import { FunctionResources } from '@aws-amplify/plugin-types'; +import { ResourceProvider } from '@aws-amplify/plugin-types'; // @public -export class AmplifyFunctionFactory implements ConstructFactory { - static build: (props: AmplifyFunctionFactoryBuildProps) => Promise; - static fromDir: (props: AmplifyFunctionFactoryFromDirProps) => AmplifyFunctionFactory; - getInstance: ({ constructContainer, }: ConstructFactoryGetInstanceProps) => AmplifyLambdaFunction; -} +export const defineFunction: (props?: FunctionProps) => ConstructFactory>; // @public (undocumented) -export type AmplifyFunctionFactoryBaseProps = { - name: string; +export type FunctionProps = { + name?: string; + entry?: string; }; -// @public (undocumented) -export type AmplifyFunctionFactoryBuildProps = AmplifyFunctionFactoryBaseProps & Omit & { - buildCommand: string; - outDir: string; -}; - -// @public (undocumented) -export type AmplifyFunctionFactoryFromDirProps = AmplifyFunctionFactoryBaseProps & Omit & { - codePath: string; -}; - -// @public -export const Func: typeof AmplifyFunctionFactory; - // (No @packageDocumentation comment for this package) ``` diff --git a/packages/backend-function/package.json b/packages/backend-function/package.json index 2e319e8d87..a4c5b576a2 100644 --- a/packages/backend-function/package.json +++ b/packages/backend-function/package.json @@ -19,13 +19,13 @@ "license": "Apache-2.0", "dependencies": { "@aws-amplify/backend-output-storage": "0.2.6", - "@aws-amplify/function-construct-alpha": "^0.2.1", "@aws-amplify/plugin-types": "^0.4.2", "execa": "^7.1.1" }, "devDependencies": { "@aws-amplify/backend-platform-test-stubs": "^0.3.1", - "@aws-amplify/platform-core": "^0.3.1" + "@aws-amplify/platform-core": "^0.3.1", + "uuid": "^9.0.1" }, "peerDependencies": { "aws-cdk-lib": "^2.110.1", diff --git a/packages/backend-function/src/factory.test.ts b/packages/backend-function/src/factory.test.ts index 3643097ec3..bb884d82ba 100644 --- a/packages/backend-function/src/factory.test.ts +++ b/packages/backend-function/src/factory.test.ts @@ -1,15 +1,16 @@ -import { beforeEach, describe, it, mock } from 'node:test'; -import { Func } from './factory.js'; +import { beforeEach, describe, it } from 'node:test'; import { App, Stack } from 'aws-cdk-lib'; import { ConstructFactoryGetInstanceProps } from '@aws-amplify/plugin-types'; import assert from 'node:assert'; -import { fileURLToPath } from 'url'; -import * as path from 'path'; import { StackMetadataBackendOutputStorageStrategy } from '@aws-amplify/backend-output-storage'; import { ConstructContainerStub, StackResolverStub, } from '@aws-amplify/backend-platform-test-stubs'; +import { defaultLambda } from './test-assets/default-lambda/resource.js'; +import { Template } from 'aws-cdk-lib/assertions'; +import { defineFunction } from './factory.js'; +import { lambdaWithDependencies } from './test-assets/lambda-with-dependencies/resource.js'; const createStackAndSetContext = (): Stack => { const app = new App(); @@ -41,38 +42,74 @@ void describe('AmplifyFunctionFactory', () => { }); void it('creates singleton function instance', () => { - const functionFactory = Func.fromDir({ - name: 'testFunc', - codePath: path.join('..', 'test-assets', 'test-lambda'), - }); + const functionFactory = defaultLambda; const instance1 = functionFactory.getInstance(getInstanceProps); const instance2 = functionFactory.getInstance(getInstanceProps); assert.strictEqual(instance1, instance2); }); - void it('executes build command from directory where constructor is used', async () => { - const commandExecutorMock = mock.fn(); + void it('resolves default name and entry when no args specified', () => { + const functionFactory = defaultLambda; + const lambda = functionFactory.getInstance(getInstanceProps); + const template = Template.fromStack(Stack.of(lambda)); + template.resourceCountIs('AWS::Lambda::Function', 1); + template.hasResourceProperties('AWS::Lambda::Function', { + Handler: 'index.handler', + }); + const lambdaLogicalId = Object.keys( + template.findResources('AWS::Lambda::Function') + )[0]; + // eslint-disable-next-line spellcheck/spell-checker + assert.ok(lambdaLogicalId.includes('defaultlambda')); + }); - // Casting to never is necessary because commandExecutor is a private method. - // TS yells that it's not a property on Func even though it is there - mock.method(Func, 'commandExecutor' as never, commandExecutorMock); + void it('resolves default name when entry specified', () => { + const functionFactory = defineFunction({ + entry: './test-assets/default-lambda/handler.ts', + }); + const lambda = functionFactory.getInstance(getInstanceProps); + const template = Template.fromStack(Stack.of(lambda)); + template.resourceCountIs('AWS::Lambda::Function', 1); + template.hasResourceProperties('AWS::Lambda::Function', { + Handler: 'index.handler', + }); + const lambdaLogicalId = Object.keys( + template.findResources('AWS::Lambda::Function') + )[0]; + assert.ok(lambdaLogicalId.includes('handler')); + }); - ( - await Func.build({ - name: 'testFunc', - outDir: path.join('..', 'test-assets', 'test-lambda'), - buildCommand: 'test command', - }) - ).getInstance(getInstanceProps); + void it('uses name and entry that is explicitly specified', () => { + const functionFactory = defineFunction({ + entry: './test-assets/default-lambda/handler.ts', + name: 'myCoolLambda', + }); + const lambda = functionFactory.getInstance(getInstanceProps); + const template = Template.fromStack(Stack.of(lambda)); + template.resourceCountIs('AWS::Lambda::Function', 1); + template.hasResourceProperties('AWS::Lambda::Function', { + Handler: 'index.handler', + }); + const lambdaLogicalId = Object.keys( + template.findResources('AWS::Lambda::Function') + )[0]; + assert.ok(lambdaLogicalId.includes('myCoolLambda')); + }); - assert.strictEqual(commandExecutorMock.mock.callCount(), 1); - assert.deepStrictEqual(commandExecutorMock.mock.calls[0].arguments, [ - 'test command', - { - cwd: fileURLToPath(new URL('../src', import.meta.url)), - stdio: 'inherit', - shell: 'bash', - }, - ]); + void it('builds lambda with local and 3p dependencies', () => { + const lambda = lambdaWithDependencies.getInstance(getInstanceProps); + const template = Template.fromStack(Stack.of(lambda)); + // There isn't a way to check the contents of the bundled lambda using the CDK Template utility + // So we just check that the lambda was created properly in the CFN template. + // There is an e2e test that validates proper lambda bundling + template.resourceCountIs('AWS::Lambda::Function', 1); + template.hasResourceProperties('AWS::Lambda::Function', { + Handler: 'index.handler', + }); + const lambdaLogicalId = Object.keys( + template.findResources('AWS::Lambda::Function') + )[0]; + // eslint-disable-next-line spellcheck/spell-checker + assert.ok(lambdaLogicalId.includes('lambdawithdependencies')); }); }); diff --git a/packages/backend-function/src/factory.ts b/packages/backend-function/src/factory.ts index c02600499c..c691cef309 100644 --- a/packages/backend-function/src/factory.ts +++ b/packages/backend-function/src/factory.ts @@ -2,137 +2,127 @@ import { ConstructContainerEntryGenerator, ConstructFactory, ConstructFactoryGetInstanceProps, + FunctionResources, + ResourceProvider, } from '@aws-amplify/plugin-types'; -import { - AmplifyFunctionProps, - AmplifyLambdaFunction, -} from '@aws-amplify/function-construct-alpha'; import { Construct } from 'constructs'; -import { execaCommand } from 'execa'; +import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'; import * as path from 'path'; import { getCallerDirectory } from './get_caller_directory.js'; -export type AmplifyFunctionFactoryBaseProps = { +/** + * Entry point for defining a function in the Amplify ecosystem + */ +export const defineFunction = ( + props: FunctionProps = {} +): ConstructFactory> => + new FunctionFactory(props, new Error().stack); + +export type FunctionProps = { /** - * A name for the function that is used to disambiguate it from other functions in the project + * A name for the function. + * Defaults to the basename of the entry path if specified. + * If no entry is specified, defaults to the directory name in which this function is defined. + * + * Example: + * If entry is `./scheduled-db-backup.ts` the name will default to "scheduled-db-backup" + * If entry is not set and the function is defined in `amplify/functions/db-backup/resource.ts` the name will default to "db-backup" */ - name: string; + name?: string; + /** + * The path to the file that contains the function entry point. + * If this is a relative path, it is computed relative to the file where this function is defined + * + * Defaults to './handler.ts' + */ + entry?: string; }; -export type AmplifyFunctionFactoryBuildProps = AmplifyFunctionFactoryBaseProps & - Omit & { - /** - * The command to run that generates built function code. - * This command is run from the directory where this factory is called - */ - buildCommand: string; - /** - * The buildCommand is expected to place build artifacts at this location. - * This path can be relative or absolute. If relative, the absolute path is calculated based on the directory where this factory is called - */ - outDir: string; - }; - -export type AmplifyFunctionFactoryFromDirProps = - AmplifyFunctionFactoryBaseProps & - Omit & { - /** - * The location of the pre-built function code. - * Can be a directory or a .zip file. - * Can be a relative or absolute path. If relative, the absolute path is calculated based on the directory where this factory is called. - */ - codePath: string; - }; - -type AmplifyFunctionFactoryProps = AmplifyFunctionFactoryBaseProps & - AmplifyFunctionProps; - /** * Create Lambda functions in the context of an Amplify backend definition */ -export class AmplifyFunctionFactory - implements ConstructFactory -{ - // execaCommand is assigned to a static prop so that it can be mocked in tests - private static commandExecutor = execaCommand; - +class FunctionFactory implements ConstructFactory { private generator: ConstructContainerEntryGenerator; /** * Create a new AmplifyFunctionFactory */ - private constructor(private readonly props: AmplifyFunctionFactoryProps) {} + constructor( + private readonly props: FunctionProps, + private readonly callerStack?: string + ) {} /** - * Create a function from a directory that contains pre-built code + * Creates an instance of AmplifyFunction within the provided Amplify context */ - static fromDir = ( - props: AmplifyFunctionFactoryFromDirProps - ): AmplifyFunctionFactory => { - const absoluteCodePath = path.isAbsolute(props.codePath) - ? props.codePath - : path.resolve(getCallerDirectory(new Error().stack), props.codePath); - return new AmplifyFunctionFactory({ - name: props.name, - absoluteCodePath, - runtime: props.runtime, - handler: props.handler, - }); + getInstance = ({ + constructContainer, + }: ConstructFactoryGetInstanceProps): AmplifyFunction => { + if (!this.generator) { + this.generator = new FunctionGenerator(this.hydrateDefaults()); + } + return constructContainer.getOrCompute(this.generator) as AmplifyFunction; }; - /** - * Create a function by executing a build command that places build artifacts at a specified location - * - * TODO: Investigate long-term function building strategy: https://github.com/aws-amplify/amplify-backend/issues/92 - */ - static build = async ( - props: AmplifyFunctionFactoryBuildProps - ): Promise => { - const importPath = getCallerDirectory(new Error().stack); - - await AmplifyFunctionFactory.commandExecutor(props.buildCommand, { - cwd: importPath, - stdio: 'inherit', - shell: 'bash', - }); + private hydrateDefaults = (): HydratedFunctionProps => { + return { + name: this.resolveName(), + entry: this.resolveEntry(), + }; + }; - const absoluteCodePath = path.isAbsolute(props.outDir) - ? props.outDir - : path.resolve(importPath, props.outDir); + private resolveName = () => { + // If name is set explicitly, use that + if (this.props.name) { + return this.props.name; + } + // If entry is set, use the basename of the entry path + if (this.props.entry) { + return path.parse(this.props.entry).name; + } - return new AmplifyFunctionFactory({ - name: props.name, - absoluteCodePath, - runtime: props.runtime, - handler: props.handler, - }); + // Otherwise, use the directory name where the function is defined + return path.basename(getCallerDirectory(this.callerStack)); }; - /** - * Creates an instance of AmplifyFunction within the provided Amplify context - */ - getInstance = ({ - constructContainer, - }: ConstructFactoryGetInstanceProps): AmplifyLambdaFunction => { - if (!this.generator) { - this.generator = new AmplifyFunctionGenerator(this.props); + private resolveEntry = () => { + // if entry is not set, default to handler.ts + if (!this.props.entry) { + return path.join(getCallerDirectory(this.callerStack), 'handler.ts'); + } + + // if entry is absolute use that + if (path.isAbsolute(this.props.entry)) { + return this.props.entry; } - return constructContainer.getOrCompute( - this.generator - ) as AmplifyLambdaFunction; + + // if entry is relative, compute with respect to the caller directory + return path.join(getCallerDirectory(this.callerStack), this.props.entry); }; } -class AmplifyFunctionGenerator implements ConstructContainerEntryGenerator { +type HydratedFunctionProps = Required; + +class FunctionGenerator implements ConstructContainerEntryGenerator { readonly resourceGroupName = 'function'; - constructor(private readonly props: AmplifyFunctionFactoryProps) {} + constructor(private readonly props: HydratedFunctionProps) {} generateContainerEntry = (scope: Construct) => { - return new AmplifyLambdaFunction(scope, this.props.name, this.props); + return new AmplifyFunction(scope, this.props.name, this.props); }; } -/** - * Alias for AmplifyFunctionFactory - */ -export const Func = AmplifyFunctionFactory; +class AmplifyFunction + extends Construct + implements ResourceProvider +{ + readonly resources: FunctionResources; + constructor(scope: Construct, id: string, props: HydratedFunctionProps) { + super(scope, id); + this.resources = { + lambda: new NodejsFunction(scope, `${id}-lambda`, { + entry: props.entry, + }), + }; + } +} diff --git a/packages/backend-function/src/test-assets/default-lambda/handler.ts b/packages/backend-function/src/test-assets/default-lambda/handler.ts new file mode 100644 index 0000000000..b980c66e83 --- /dev/null +++ b/packages/backend-function/src/test-assets/default-lambda/handler.ts @@ -0,0 +1,6 @@ +/** + * Hello world lambda used for testing defaults to `defineFunction` + */ +export const handler = async () => { + return 'hello world lambda'; +}; diff --git a/packages/backend-function/src/test-assets/default-lambda/resource.ts b/packages/backend-function/src/test-assets/default-lambda/resource.ts new file mode 100644 index 0000000000..bfa80c0e97 --- /dev/null +++ b/packages/backend-function/src/test-assets/default-lambda/resource.ts @@ -0,0 +1,7 @@ +import { defineFunction } from '../../factory.js'; + +/** + * Because the defineFunction() defaults depend on a specific file convention, + * we are defining a test asset here where the directory structure can be controlled + */ +export const defaultLambda = defineFunction(); diff --git a/packages/backend-function/src/test-assets/lambda-with-dependencies/handler.ts b/packages/backend-function/src/test-assets/lambda-with-dependencies/handler.ts new file mode 100644 index 0000000000..5af50164c1 --- /dev/null +++ b/packages/backend-function/src/test-assets/lambda-with-dependencies/handler.ts @@ -0,0 +1,6 @@ +import { getResponse } from './response_generator.js'; + +/** + * Dummy lambda handler to test building a function with a local import + */ +export const handler = async () => getResponse(); diff --git a/packages/backend-function/src/test-assets/lambda-with-dependencies/resource.ts b/packages/backend-function/src/test-assets/lambda-with-dependencies/resource.ts new file mode 100644 index 0000000000..d6a769e02f --- /dev/null +++ b/packages/backend-function/src/test-assets/lambda-with-dependencies/resource.ts @@ -0,0 +1,3 @@ +import { defineFunction } from '../../factory.js'; + +export const lambdaWithDependencies = defineFunction(); diff --git a/packages/backend-function/src/test-assets/lambda-with-dependencies/response_generator.ts b/packages/backend-function/src/test-assets/lambda-with-dependencies/response_generator.ts new file mode 100644 index 0000000000..ff6431ceb6 --- /dev/null +++ b/packages/backend-function/src/test-assets/lambda-with-dependencies/response_generator.ts @@ -0,0 +1,6 @@ +import { v4 as uuid } from 'uuid'; + +/** + * Dummy function to test building a lambda that has a 3p import + */ +export const getResponse = () => `Your uuid is ${uuid()}`; diff --git a/packages/backend-function/test-assets/test-lambda/mock.txt b/packages/backend-function/test-assets/test-lambda/mock.txt deleted file mode 100644 index 29cc220aee..0000000000 --- a/packages/backend-function/test-assets/test-lambda/mock.txt +++ /dev/null @@ -1,2 +0,0 @@ -To test out creating a lambda we need a directory that simulates the lambda content. -Obviously this is not a real lambda, but it allows CDK synth to proceed. diff --git a/packages/backend-function/tsconfig.json b/packages/backend-function/tsconfig.json index 7ac631bb37..36aca79e32 100644 --- a/packages/backend-function/tsconfig.json +++ b/packages/backend-function/tsconfig.json @@ -3,7 +3,6 @@ "compilerOptions": { "rootDir": "src", "outDir": "lib" }, "references": [ { "path": "../backend-output-storage" }, - { "path": "../function-construct" }, { "path": "../plugin-types" }, { "path": "../backend-platform-test-stubs" }, { "path": "../platform-core" } diff --git a/packages/backend/API.md b/packages/backend/API.md index 1a7e111cc4..edd546358d 100644 --- a/packages/backend/API.md +++ b/packages/backend/API.md @@ -11,8 +11,8 @@ import { Construct } from 'constructs'; import { ConstructFactory } from '@aws-amplify/plugin-types'; import { defineAuth } from '@aws-amplify/backend-auth'; import { defineData } from '@aws-amplify/backend-data'; +import { defineFunction } from '@aws-amplify/backend-function'; import { defineStorage } from '@aws-amplify/backend-storage'; -import { Func } from '@aws-amplify/backend-function'; import { Stack } from 'aws-cdk-lib'; export { a } @@ -34,9 +34,9 @@ export const defineBackend: BackendSecret; diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index db1eb4bfbf..039b5de54c 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -15,4 +15,4 @@ export { defineAuth } from '@aws-amplify/backend-auth'; export { defineStorage } from '@aws-amplify/backend-storage'; // function -export { Func } from '@aws-amplify/backend-function'; +export { defineFunction } from '@aws-amplify/backend-function'; diff --git a/packages/create-amplify/templates/basic-auth-data/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json b/packages/create-amplify/templates/basic-auth-data/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json index b5e2c64de0..b4338725ea 100644 --- a/packages/create-amplify/templates/basic-auth-data/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json +++ b/packages/create-amplify/templates/basic-auth-data/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json @@ -421,7 +421,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/94663ad34627ee131e3d96f0aebd8bdccee2f3db588fc658564562b4eb233b1f.json" + "/2a0d1b7fb776ba17bf31c9284802781a25e434b93f98845b46620760e48fa284.json" ] ] } diff --git a/packages/create-amplify/templates/basic-auth-data/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json b/packages/create-amplify/templates/basic-auth-data/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json index 1196b355a6..1929590fd3 100644 --- a/packages/create-amplify/templates/basic-auth-data/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json +++ b/packages/create-amplify/templates/basic-auth-data/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json @@ -47,7 +47,7 @@ "ApiId" ] }, - "Expires": 1703801369 + "Expires": 1703878641 } }, "amplifyDataGraphQLAPINONEDS684BF699": { diff --git a/packages/function-construct/.npmignore b/packages/function-construct/.npmignore deleted file mode 100644 index dbde1fb5db..0000000000 --- a/packages/function-construct/.npmignore +++ /dev/null @@ -1,14 +0,0 @@ -# Be very careful editing this file. It is crafted to work around [this issue](https://github.com/npm/npm/issues/4479) - -# First ignore everything -**/* - -# Then add back in transpiled js and ts declaration files -!lib/**/*.js -!lib/**/*.d.ts - -# Then ignore test js and ts declaration files -*.test.js -*.test.d.ts - -# This leaves us with including only js and ts declaration files of functional code diff --git a/packages/function-construct/API.md b/packages/function-construct/API.md deleted file mode 100644 index 34a1f63495..0000000000 --- a/packages/function-construct/API.md +++ /dev/null @@ -1,28 +0,0 @@ -## API Report File for "@aws-amplify/function-construct-alpha" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts - -import { AmplifyFunction } from '@aws-amplify/plugin-types'; -import { Construct } from 'constructs'; -import { FunctionResources } from '@aws-amplify/plugin-types'; -import { Runtime } from 'aws-cdk-lib/aws-lambda'; - -// @public (undocumented) -export type AmplifyFunctionProps = { - absoluteCodePath: string; - runtime?: Runtime; - handler?: string; -}; - -// @public -export class AmplifyLambdaFunction extends Construct implements AmplifyFunction { - constructor(scope: Construct, id: string, props: AmplifyFunctionProps); - // (undocumented) - readonly resources: FunctionResources; -} - -// (No @packageDocumentation comment for this package) - -``` diff --git a/packages/function-construct/CHANGELOG.md b/packages/function-construct/CHANGELOG.md deleted file mode 100644 index b42b78716e..0000000000 --- a/packages/function-construct/CHANGELOG.md +++ /dev/null @@ -1,87 +0,0 @@ -# @aws-amplify/function-construct-alpha - -## 0.2.1 - -### Patch Changes - -- 5ed51cbd5: Upgrade aws-cdk to 2.110.1 -- Updated dependencies [5ed51cbd5] - - @aws-amplify/backend-output-storage@0.2.6 - -## 0.2.0 - -### Minor Changes - -- 47456c26: Store attribution metadata in stack descriptions - -### Patch Changes - -- b2b0c2da: force version bump -- 7296e9d9: Initial publish -- 7103735b: cdk lib dependency declaration -- 3c36ace9: Implement UserPool trigger config -- 36d93e46: add license to package.json -- 8f99476e: chore: upgrade aws-cdk to 2.103.0 -- 59f5ea24: chore: upgrade aws-cdk to 2.100.0 -- Updated dependencies [47456c26] -- Updated dependencies [ac3df080] -- Updated dependencies [0398b8e1] -- Updated dependencies [36d93e46] -- Updated dependencies [8f99476e] -- Updated dependencies [f75fa531] -- Updated dependencies [883d9da7] -- Updated dependencies [59f5ea24] - - @aws-amplify/backend-output-storage@0.2.0 - -## 0.2.0-alpha.7 - -### Minor Changes - -- 47456c26: Store attribution metadata in stack descriptions - -### Patch Changes - -- Updated dependencies [47456c26] - - @aws-amplify/backend-output-storage@0.2.0-alpha.6 - -## 0.1.1-alpha.6 - -### Patch Changes - -- 8f99476e: chore: upgrade aws-cdk to 2.103.0 - -## 0.1.1-alpha.5 - -### Patch Changes - -- 59f5ea24: chore: upgrade aws-cdk to 2.100.0 - -## 0.1.1-alpha.4 - -### Patch Changes - -- 7103735b: cdk lib dependency declaration - -## 0.1.1-alpha.3 - -### Patch Changes - -- 36d93e46: add license to package.json - -## 0.1.1-alpha.2 - -### Patch Changes - -- 3c36ace: Implement UserPool trigger config - -## 0.1.1-alpha.1 - -### Patch Changes - -- b2b0c2d: force version bump - -## 0.1.1-alpha.0 - -### Patch Changes - -- 7296e9d: Initial publish diff --git a/packages/function-construct/api-extractor.json b/packages/function-construct/api-extractor.json deleted file mode 100644 index 0f56de03f6..0000000000 --- a/packages/function-construct/api-extractor.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../api-extractor.base.json" -} diff --git a/packages/function-construct/package.json b/packages/function-construct/package.json deleted file mode 100644 index 7d7f7cb67b..0000000000 --- a/packages/function-construct/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@aws-amplify/function-construct-alpha", - "version": "0.2.1", - "type": "module", - "publishConfig": { - "access": "public" - }, - "exports": { - ".": { - "types": "./lib/index.d.ts", - "import": "./lib/index.js", - "require": "./lib/index.js" - } - }, - "types": "lib/index.d.ts", - "scripts": { - "update:api": "api-extractor run --local" - }, - "license": "Apache-2.0", - "dependencies": { - "@aws-amplify/backend-output-storage": "^0.2.6" - }, - "peerDependencies": { - "aws-cdk-lib": "^2.110.1", - "constructs": "^10.0.0" - } -} diff --git a/packages/function-construct/src/construct.test.ts b/packages/function-construct/src/construct.test.ts deleted file mode 100644 index b5755accf1..0000000000 --- a/packages/function-construct/src/construct.test.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { beforeEach, describe, it } from 'node:test'; -import { App, Stack } from 'aws-cdk-lib'; -import { Template } from 'aws-cdk-lib/assertions'; -import { AmplifyLambdaFunction } from './construct.js'; -import { Runtime } from 'aws-cdk-lib/aws-lambda'; -import { fileURLToPath } from 'url'; -import assert from 'node:assert'; - -const testCodePath = fileURLToPath( - new URL('../test-assets/test-lambda', import.meta.url) -); - -void describe('AmplifyFunction', () => { - let stack: Stack; - beforeEach(() => { - const app = new App(); - stack = new Stack(app); - }); - void it('creates lambda with specified runtime', () => { - new AmplifyLambdaFunction(stack, 'test', { - absoluteCodePath: testCodePath, - runtime: Runtime.JAVA_8, - }); - const template = Template.fromStack(stack); - template.hasResourceProperties('AWS::Lambda::Function', { - Runtime: 'java8', - }); - }); - - void it('creates lambda with default runtime', () => { - new AmplifyLambdaFunction(stack, 'test', { - absoluteCodePath: testCodePath, - }); - const template = Template.fromStack(stack); - template.hasResourceProperties('AWS::Lambda::Function', { - Runtime: 'nodejs18.x', - }); - }); - - void it('creates lambda with specified handler', () => { - new AmplifyLambdaFunction(stack, 'test', { - absoluteCodePath: testCodePath, - handler: 'test.main', - }); - const template = Template.fromStack(stack); - template.hasResourceProperties('AWS::Lambda::Function', { - Handler: 'test.main', - }); - }); - - void it('creates lambda with default handler', () => { - new AmplifyLambdaFunction(stack, 'test', { - absoluteCodePath: testCodePath, - }); - const template = Template.fromStack(stack); - template.hasResourceProperties('AWS::Lambda::Function', { - Handler: 'index.handler', - }); - }); - - void it('stores attribution data in stack', () => { - const app = new App(); - const stack = new Stack(app); - new AmplifyLambdaFunction(stack, 'testAuth', { - absoluteCodePath: testCodePath, - }); - - const template = Template.fromStack(stack); - assert.equal( - JSON.parse(template.toJSON().Description).stackType, - 'function-Lambda' - ); - }); -}); diff --git a/packages/function-construct/src/construct.ts b/packages/function-construct/src/construct.ts deleted file mode 100644 index 19167c510a..0000000000 --- a/packages/function-construct/src/construct.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Construct } from 'constructs'; -import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; -import { AmplifyFunction, FunctionResources } from '@aws-amplify/plugin-types'; -import { AttributionMetadataStorage } from '@aws-amplify/backend-output-storage'; -import { Stack } from 'aws-cdk-lib'; -import { fileURLToPath } from 'url'; - -// Be very careful editing this value. It is the string that is used to attribute stacks to Amplify Function in BI metrics -const functionStackType = 'function-Lambda'; - -export type AmplifyFunctionProps = { - absoluteCodePath: string; - runtime?: Runtime; - handler?: string; -}; - -/** - * Hello world construct implementation - */ -export class AmplifyLambdaFunction - extends Construct - implements AmplifyFunction -{ - readonly resources: FunctionResources; - /** - * Create a new AmplifyConstruct - */ - constructor(scope: Construct, id: string, props: AmplifyFunctionProps) { - super(scope, id); - - this.resources = { - lambda: new Function(this, `${id}LambdaFunction`, { - code: Code.fromAsset(props.absoluteCodePath), - runtime: props.runtime || Runtime.NODEJS_18_X, - handler: props.handler || 'index.handler', - }), - }; - - new AttributionMetadataStorage().storeAttributionMetadata( - Stack.of(this), - functionStackType, - fileURLToPath(new URL('../package.json', import.meta.url)) - ); - } -} diff --git a/packages/function-construct/src/index.ts b/packages/function-construct/src/index.ts deleted file mode 100644 index 9d1f8f790c..0000000000 --- a/packages/function-construct/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './construct.js'; diff --git a/packages/function-construct/test-assets/test-lambda/mock.txt b/packages/function-construct/test-assets/test-lambda/mock.txt deleted file mode 100644 index 29cc220aee..0000000000 --- a/packages/function-construct/test-assets/test-lambda/mock.txt +++ /dev/null @@ -1,2 +0,0 @@ -To test out creating a lambda we need a directory that simulates the lambda content. -Obviously this is not a real lambda, but it allows CDK synth to proceed. diff --git a/packages/function-construct/tsconfig.json b/packages/function-construct/tsconfig.json deleted file mode 100644 index 74efb05dd0..0000000000 --- a/packages/function-construct/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { "rootDir": "src", "outDir": "lib" }, - "references": [{ "path": "../backend-output-storage" }] -} diff --git a/packages/function-construct/typedoc.json b/packages/function-construct/typedoc.json deleted file mode 100644 index 35fed2c958..0000000000 --- a/packages/function-construct/typedoc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "entryPoints": ["src/index.ts"] -} diff --git a/packages/integration-tests/package.json b/packages/integration-tests/package.json index c3523397cc..07cc221c66 100644 --- a/packages/integration-tests/package.json +++ b/packages/integration-tests/package.json @@ -10,12 +10,14 @@ "@aws-amplify/backend-storage": "0.3.1", "@aws-amplify/client-config": "^0.4.0", "@aws-amplify/data-schema": "^0.12.9", + "@aws-amplify/platform-core": "^0.3.1", "@aws-sdk/client-amplify": "^3.440.0", "@aws-sdk/client-cloudformation": "^3.421.0", - "@aws-amplify/platform-core": "^0.3.1", + "@aws-sdk/client-lambda": "^3.460.0", "execa": "^8.0.1", "fs-extra": "^11.1.1", - "glob": "^10.2.7" + "glob": "^10.2.7", + "uuid": "^9.0.1" }, "scripts": { "update:api": "api-extractor run --local" diff --git a/packages/integration-tests/src/find_deployed_resource.ts b/packages/integration-tests/src/find_deployed_resource.ts new file mode 100644 index 0000000000..ee52620b06 --- /dev/null +++ b/packages/integration-tests/src/find_deployed_resource.ts @@ -0,0 +1,61 @@ +import { BackendIdentifier } from '@aws-amplify/plugin-types'; +import { + CloudFormationClient, + DescribeStackResourcesCommand, +} from '@aws-sdk/client-cloudformation'; +import { BackendIdentifierConversions } from '@aws-amplify/platform-core'; + +export type StringPredicate = (str: string) => boolean; + +/** + * Class that finds resource physical ids in a deployed stack + */ +export class DeployedResourcesFinder { + /** + * Construct with a cfnClient + */ + constructor(private readonly cfnClient: CloudFormationClient) {} + + /** + * Find resources of type "resourceType" within the stack defined by "backendId" + * Optionally, filter physical names by a predicate + * @param backendId Used to determine which CFN stack to look in + * @param resourceType The CFN resource type to look for. Eg "AWS::Lambda::Function" or "AWS::IAM::Role" + * @param physicalNamePredicate Optional predicate to filter physical names of resources matching resourceType + */ + find = async ( + backendId: BackendIdentifier, + resourceType: string, + physicalNamePredicate: StringPredicate = () => true // match all resources of "resourceType" by default + ): Promise => { + const stackName = BackendIdentifierConversions.toStackName(backendId); + + const queue = [stackName]; + + const resourcePhysicalIds: string[] = []; + + while (queue.length > 0) { + const currentStack = queue.pop(); + const response = await this.cfnClient.send( + new DescribeStackResourcesCommand({ StackName: currentStack }) + ); + + for (const resource of response.StackResources || []) { + if ( + resource.ResourceType === 'AWS::CloudFormation::Stack' && + resource.PhysicalResourceId + ) { + queue.unshift(resource.PhysicalResourceId); + } else if ( + resource.ResourceType === resourceType && + resource.PhysicalResourceId && + physicalNamePredicate(resource.PhysicalResourceId) + ) { + resourcePhysicalIds.push(resource.PhysicalResourceId); + } + } + } + + return resourcePhysicalIds; + }; +} diff --git a/packages/integration-tests/src/test-e2e/deployment.test.ts b/packages/integration-tests/src/test-e2e/deployment.test.ts index 910c7ed9e3..8799a32361 100644 --- a/packages/integration-tests/src/test-e2e/deployment.test.ts +++ b/packages/integration-tests/src/test-e2e/deployment.test.ts @@ -58,7 +58,7 @@ void describe( void it(`[${testProjectCreator.name}] deploys fully`, async () => { await testProject.deploy(branchBackendIdentifier); - await testProject.assertPostDeployment(); + await testProject.assertPostDeployment(branchBackendIdentifier); const testBranchDetails = await amplifyAppPool.fetchTestBranchDetails( testBranch ); @@ -123,7 +123,7 @@ void describe( void describe('in sequence', { concurrency: false }, () => { void it(`[${testProjectCreator.name}] deploys fully`, async () => { await testProject.deploy(sandboxBackendIdentifier); - await testProject.assertPostDeployment(); + await testProject.assertPostDeployment(sandboxBackendIdentifier); }); void it(`[${testProjectCreator.name}] hot-swaps a change`, async () => { @@ -145,7 +145,7 @@ void describe( .do(rejectCleanupSandbox()) .run(); - await testProject.assertPostDeployment(); + await testProject.assertPostDeployment(sandboxBackendIdentifier); }); }); }); diff --git a/packages/integration-tests/src/test-project-setup/data_storage_auth_with_triggers.ts b/packages/integration-tests/src/test-project-setup/data_storage_auth_with_triggers.ts index 9a64df3b29..b5d19abe61 100644 --- a/packages/integration-tests/src/test-project-setup/data_storage_auth_with_triggers.ts +++ b/packages/integration-tests/src/test-project-setup/data_storage_auth_with_triggers.ts @@ -7,6 +7,9 @@ import { TestProjectBase, TestProjectUpdate } from './test_project_base.js'; import { fileURLToPath, pathToFileURL } from 'url'; import path from 'path'; import { TestProjectCreator } from './test_project_creator.js'; +import { DeployedResourcesFinder } from '../find_deployed_resource.js'; +import assert from 'node:assert'; +import { InvokeCommand, LambdaClient } from '@aws-sdk/client-lambda'; type TestConstant = { secretNames: { @@ -27,7 +30,9 @@ export class DataStorageAuthWithTriggerTestProjectCreator */ constructor( private readonly cfnClient: CloudFormationClient, - private readonly secretClient: SecretClient + private readonly secretClient: SecretClient, + private readonly lambdaClient: LambdaClient, + private readonly resourceFinder: DeployedResourcesFinder ) {} createProject = async (e2eProjectDir: string): Promise => { @@ -39,7 +44,9 @@ export class DataStorageAuthWithTriggerTestProjectCreator projectRoot, projectAmplifyDir, this.cfnClient, - this.secretClient + this.secretClient, + this.lambdaClient, + this.resourceFinder ); await fs.cp( project.sourceProjectAmplifyDirPath, @@ -86,7 +93,9 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase { projectDirPath: string, projectAmplifyDirPath: string, cfnClient: CloudFormationClient, - private readonly secretClient: SecretClient + private readonly secretClient: SecretClient, + private readonly lambdaClient: LambdaClient, + private readonly resourceFinder: DeployedResourcesFinder ) { super(name, projectDirPath, projectAmplifyDirPath, cfnClient); } @@ -129,7 +138,39 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase { ]; } - setUpDeployEnvironment = async ( + override async assertPostDeployment( + backendId: BackendIdentifier + ): Promise { + await super.assertPostDeployment(backendId); + + // Check that deployed lambda is working correctly + + // find lambda function + const lambdas = await this.resourceFinder.find( + backendId, + 'AWS::Lambda::Function', + (name) => name.includes('specialTestFunction') + ); + + assert.equal(lambdas.length, 1); + + // invoke the lambda + const response = await this.lambdaClient.send( + new InvokeCommand({ FunctionName: lambdas[0] }) + ); + const responsePayload = JSON.parse( + response.Payload?.transformToString() || '' + ); + + // check expected response + assert.equal( + responsePayload, + // eslint-disable-next-line spellcheck/spell-checker + 'Your uuid is 6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b' + ); + } + + private setUpDeployEnvironment = async ( backendId: BackendIdentifier ): Promise => { const { secretNames } = (await import( @@ -142,7 +183,7 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase { } }; - clearDeployEnvironment = async ( + private clearDeployEnvironment = async ( backendId: BackendIdentifier ): Promise => { const { secretNames } = (await import( diff --git a/packages/integration-tests/src/test-project-setup/test_project_base.ts b/packages/integration-tests/src/test-project-setup/test_project_base.ts index d70a845592..f7b6013211 100644 --- a/packages/integration-tests/src/test-project-setup/test_project_base.ts +++ b/packages/integration-tests/src/test-project-setup/test_project_base.ts @@ -41,7 +41,7 @@ export abstract class TestProjectBase { readonly name: string, readonly projectDirPath: string, readonly projectAmplifyDirPath: string, - private readonly cfnClient: CloudFormationClient + protected readonly cfnClient: CloudFormationClient ) {} /** @@ -99,7 +99,9 @@ export abstract class TestProjectBase { /** * Verify the project after deployment. */ - async assertPostDeployment(): Promise { + // suppressing because subclass implementations can use backendId + // eslint-disable-next-line @typescript-eslint/no-unused-vars + async assertPostDeployment(backendId: BackendIdentifier): Promise { await this.assertClientConfigExists( this.projectDirPath, ClientConfigFormat.JSON diff --git a/packages/integration-tests/src/test-project-setup/test_project_creator.ts b/packages/integration-tests/src/test-project-setup/test_project_creator.ts index 088cbf5029..feba93ec0f 100644 --- a/packages/integration-tests/src/test-project-setup/test_project_creator.ts +++ b/packages/integration-tests/src/test-project-setup/test_project_creator.ts @@ -3,6 +3,8 @@ import { CloudFormationClient } from '@aws-sdk/client-cloudformation'; import { getSecretClient } from '@aws-amplify/backend-secret'; import { DataStorageAuthWithTriggerTestProjectCreator } from './data_storage_auth_with_triggers.js'; import { MinimalWithTypescriptIdiomTestProjectCreator } from './minimal_with_typescript_idioms.js'; +import { LambdaClient } from '@aws-sdk/client-lambda'; +import { DeployedResourcesFinder } from '../find_deployed_resource.js'; export type TestProjectCreator = { readonly name: string; @@ -15,9 +17,16 @@ export type TestProjectCreator = { export const getTestProjectCreators = (): TestProjectCreator[] => { const testProjectCreators: TestProjectCreator[] = []; const cfnClient = new CloudFormationClient(); + const lambdaClient = new LambdaClient(); + const resourceFinder = new DeployedResourcesFinder(cfnClient); const secretClient = getSecretClient(); testProjectCreators.push( - new DataStorageAuthWithTriggerTestProjectCreator(cfnClient, secretClient), + new DataStorageAuthWithTriggerTestProjectCreator( + cfnClient, + secretClient, + lambdaClient, + resourceFinder + ), new MinimalWithTypescriptIdiomTestProjectCreator(cfnClient) ); return testProjectCreators; diff --git a/packages/integration-tests/test-projects/data-iterative-deploy/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json b/packages/integration-tests/test-projects/data-iterative-deploy/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json index 9211743d83..e9560a8602 100644 --- a/packages/integration-tests/test-projects/data-iterative-deploy/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json +++ b/packages/integration-tests/test-projects/data-iterative-deploy/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json @@ -306,7 +306,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/57f1f5883b3e09b18ae0032ff0869df039e028f57d981ec2043772d452221c5b.json" + "/553ca6a57a97283020aca125028d777d295440a941623084927d281faea59446.json" ] ] } diff --git a/packages/integration-tests/test-projects/data-iterative-deploy/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json b/packages/integration-tests/test-projects/data-iterative-deploy/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json index d02044c679..016121d042 100644 --- a/packages/integration-tests/test-projects/data-iterative-deploy/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json +++ b/packages/integration-tests/test-projects/data-iterative-deploy/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json @@ -31,7 +31,7 @@ "ApiId" ] }, - "Expires": 1701814158 + "Expires": 1701891434 } }, "amplifyDataGraphQLAPINONEDS684BF699": { diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/echo/handler.cjs b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/echo/handler.cjs new file mode 100644 index 0000000000..a74409aa20 --- /dev/null +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/echo/handler.cjs @@ -0,0 +1,6 @@ +/** + * Hello world lambda used for testing + */ +export const handler = async () => { + return 'hello world lambda'; +}; diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/echo/mock.txt b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/echo/mock.txt deleted file mode 100644 index 5e253db13e..0000000000 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/echo/mock.txt +++ /dev/null @@ -1,2 +0,0 @@ -To test out creating a lambda we need a directory that simulates the lambda content. -Obviously this is not a real lambda, but it allows CDK synth to proceed. diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/resource.cjs b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/resource.cjs index b43b5a1955..c0d0765e31 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/resource.cjs +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/data/resource.cjs @@ -1,6 +1,6 @@ 'use strict'; -const { Func, defineData } = require('@aws-amplify/backend'); +const { defineFunction, defineData } = require('@aws-amplify/backend'); const { myFunc } = require('../function.cjs'); @@ -23,9 +23,9 @@ const data = defineData({ reverse: myFunc, // Leaving explicit Func invocation here, // ensuring we can use functions not added to `defineBackend`. - echo: Func.fromDir({ + echo: defineFunction({ name: 'echoFunc', - codePath: './echo', + entry: './echo/handler.cjs', }), }, }); diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/func-src/handler.cjs b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/func-src/handler.cjs new file mode 100644 index 0000000000..a74409aa20 --- /dev/null +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/func-src/handler.cjs @@ -0,0 +1,6 @@ +/** + * Hello world lambda used for testing + */ +export const handler = async () => { + return 'hello world lambda'; +}; diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/func-src/mock.txt b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/func-src/mock.txt deleted file mode 100644 index 29cc220aee..0000000000 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/func-src/mock.txt +++ /dev/null @@ -1,2 +0,0 @@ -To test out creating a lambda we need a directory that simulates the lambda content. -Obviously this is not a real lambda, but it allows CDK synth to proceed. diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/function.cjs b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/function.cjs index 091b0fc78a..1e30c21fe9 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/function.cjs +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/amplify/function.cjs @@ -1,10 +1,9 @@ 'use strict'; -const { Func } = require('@aws-amplify/backend'); +const { defineFunction } = require('@aws-amplify/backend'); -const myFunc = Func.fromDir({ - name: 'testFunc', - codePath: './func-src', +const myFunc = defineFunction({ + entry: './func-src/handler.cjs', }); module.exports = { myFunc }; diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json index 6e19bd01a9..9def60df8d 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json @@ -391,10 +391,10 @@ "Type": "AWS::CloudFormation::Stack", "Properties": { "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Fn::GetAtt": [ "function1351588B", - "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" ] } }, @@ -414,7 +414,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/87aeaefe934ca0965957f8dd07a34567bd92cabf3305a2f27bf7d4da171a7b6f.json" + "/601efeefc2f118029b329879a8fe6e995a9c76c75e5ee99588f1b68113b5436f.json" ] ] } @@ -441,7 +441,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/fffd6fccba429f67fbf54e07b891ec22c20a81177a051793869310e6e94b2a73.json" + "/0fbde414ebb3daeaffe0b031f48a97af5b1b5a8e4a7c66e884bbed5962311d38.json" ] ] } @@ -504,16 +504,16 @@ "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthIdentityPool7404D50ERef" ] }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Fn::GetAtt": [ "function1351588B", - "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" ] }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Fn::GetAtt": [ "function1351588B", - "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" ] } }, @@ -533,7 +533,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/297077e3e6a1808350dfa1c8959f7f7335d51bd57c6bfbccc629f3ddb2e57d7b.json" + "/38d65f8333e6b54dd31e1d08c25bfacf5d46103d4d3968f5cc433339bb5213a3.json" ] ] } diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json index 81f31dbdab..100298eab8 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json @@ -316,7 +316,7 @@ "EmailVerificationSubject": "Verify your new account", "LambdaConfig": { "PostConfirmation": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" } }, "Policies": { @@ -362,7 +362,7 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" }, "Principal": "cognito-idp.amazonaws.com", "SourceArn": { @@ -644,7 +644,7 @@ } }, "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Type": "String" } }, diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json index 707307fd1a..729291545d 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json @@ -163,8 +163,8 @@ "Type": "AWS::CloudFormation::Stack", "Properties": { "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" }, "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataGraphQLAPI8E80FACEApiId": { "Fn::GetAtt": [ @@ -178,8 +178,8 @@ "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854aauthNestedStackauthNestedStackResource462F2942OutputsamplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthunauthenticatedUserRoleF922AD28Ref": { "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854aauthNestedStackauthNestedStackResource462F2942OutputsamplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthunauthenticatedUserRoleF922AD28Ref" }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" } }, "TemplateURL": { @@ -198,7 +198,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/390aa9db25a635decfe8354f0dd4e83f6cfe506d71adfd3998181733a678ed01.json" + "/0848bc21a07a9344b4254cf3c2499684d7ae926068bb57f946e7ce996d0e4d0b.json" ] ] } @@ -606,10 +606,10 @@ "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854aauthNestedStackauthNestedStackResource462F2942OutputsamplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthIdentityPool7404D50ERef": { "Type": "String" }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Type": "String" }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Type": "String" } }, diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json index 581f089885..15e925d2cc 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json @@ -41,14 +41,14 @@ "Effect": "Allow", "Resource": [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" }, { "Fn::Join": [ "", [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" }, ":*" ] @@ -75,7 +75,7 @@ }, "LambdaConfig": { "LambdaFunctionArn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" } }, "Name": "ReverseLambdaDataSource", @@ -188,14 +188,14 @@ "Effect": "Allow", "Resource": [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" }, { "Fn::Join": [ "", [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" }, ":*" ] @@ -222,7 +222,7 @@ }, "LambdaConfig": { "LambdaFunctionArn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" } }, "Name": "EchoLambdaDataSource", @@ -310,7 +310,7 @@ } }, "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Type": "String" }, "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataGraphQLAPI8E80FACEApiId": { @@ -322,7 +322,7 @@ "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854aauthNestedStackauthNestedStackResource462F2942OutputsamplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthunauthenticatedUserRoleF922AD28Ref": { "Type": "String" }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Type": "String" } } diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json index efecf44653..acfde71c9e 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json @@ -1,7 +1,6 @@ { - "Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"AmplifyPipelineDeploy\",\"createdWith\":\"0.2.1\",\"stackType\":\"function-Lambda\",\"metadata\":{}}", "Resources": { - "testFunctestFuncLambdaFunctionServiceRole09E19D41": { + "handlerlambdaServiceRole46D7AF61": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -32,29 +31,34 @@ ] } }, - "testFunctestFuncLambdaFunction419C520E": { + "handlerlambdaE29D1580": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "S3Key": "efe12e580179d925ecc56ede6195533f23db3a8e887169b63ecb5cc644193f2b.zip" + "S3Key": "6affc7e3567ce94c11b3c71fb1bc09a11e1804ba57a291c7eab4b9c9d4b82e80.zip" + }, + "Environment": { + "Variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "testFunctestFuncLambdaFunctionServiceRole09E19D41", + "handlerlambdaServiceRole46D7AF61", "Arn" ] }, - "Runtime": "nodejs18.x" + "Runtime": "nodejs16.x" }, "DependsOn": [ - "testFunctestFuncLambdaFunctionServiceRole09E19D41" + "handlerlambdaServiceRole46D7AF61" ] }, - "echoFuncechoFuncLambdaFunctionServiceRoleE30E6459": { + "echoFunclambdaServiceRoleF37965D7": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -85,42 +89,47 @@ ] } }, - "echoFuncechoFuncLambdaFunction08680056": { + "echoFunclambdaE17DCA46": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "S3Key": "efe12e580179d925ecc56ede6195533f23db3a8e887169b63ecb5cc644193f2b.zip" + "S3Key": "3432360d5f85e129a10ef49dc990538a80a6347de86143eb4e1cce2529f7145a.zip" + }, + "Environment": { + "Variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "echoFuncechoFuncLambdaFunctionServiceRoleE30E6459", + "echoFunclambdaServiceRoleF37965D7", "Arn" ] }, - "Runtime": "nodejs18.x" + "Runtime": "nodejs16.x" }, "DependsOn": [ - "echoFuncechoFuncLambdaFunctionServiceRoleE30E6459" + "echoFunclambdaServiceRoleF37965D7" ] } }, "Outputs": { - "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Value": { "Fn::GetAtt": [ - "testFunctestFuncLambdaFunction419C520E", + "handlerlambdaE29D1580", "Arn" ] } }, - "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Value": { "Fn::GetAtt": [ - "echoFuncechoFuncLambdaFunction08680056", + "echoFunclambdaE17DCA46", "Arn" ] } diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/update-1/data/resource.ts b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/update-1/data/resource.ts index c89ae4cc0e..a6ef53f3a6 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/update-1/data/resource.ts +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-cjs/update-1/data/resource.ts @@ -1,4 +1,4 @@ -import { defineData } from '@aws-amplify/backend-graphql'; +import { defineData } from '@aws-amplify/backend'; const schema = ` input AMPLIFY {globalAuthRule: AuthRule = { allow: public }} # FOR TESTING ONLY! diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/echo/handler.js b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/echo/handler.js new file mode 100644 index 0000000000..a74409aa20 --- /dev/null +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/echo/handler.js @@ -0,0 +1,6 @@ +/** + * Hello world lambda used for testing + */ +export const handler = async () => { + return 'hello world lambda'; +}; diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/echo/mock.txt b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/echo/mock.txt deleted file mode 100644 index 5e253db13e..0000000000 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/echo/mock.txt +++ /dev/null @@ -1,2 +0,0 @@ -To test out creating a lambda we need a directory that simulates the lambda content. -Obviously this is not a real lambda, but it allows CDK synth to proceed. diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/resource.js b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/resource.js index eaf9de136d..3bf17f3578 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/resource.js +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/data/resource.js @@ -1,4 +1,4 @@ -import { Func, defineData } from '@aws-amplify/backend'; +import { defineData, defineFunction } from '@aws-amplify/backend'; import { myFunc } from '../function'; const schema = ` @@ -20,9 +20,9 @@ export const data = defineData({ reverse: myFunc, // Leaving explicit Func invocation here, // ensuring we can use functions not added to `defineBackend`. - echo: Func.fromDir({ + echo: defineFunction({ name: 'echoFunc', - codePath: './echo', + entry: './echo/handler.js', }), }, }); diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/func-src/handler.js b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/func-src/handler.js new file mode 100644 index 0000000000..a74409aa20 --- /dev/null +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/func-src/handler.js @@ -0,0 +1,6 @@ +/** + * Hello world lambda used for testing + */ +export const handler = async () => { + return 'hello world lambda'; +}; diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/func-src/mock.txt b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/func-src/mock.txt deleted file mode 100644 index 29cc220aee..0000000000 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/func-src/mock.txt +++ /dev/null @@ -1,2 +0,0 @@ -To test out creating a lambda we need a directory that simulates the lambda content. -Obviously this is not a real lambda, but it allows CDK synth to proceed. diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/function.js b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/function.js index ea270c6747..3c8b2a4840 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/function.js +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/amplify/function.js @@ -1,6 +1,5 @@ -import { Func } from '@aws-amplify/backend'; +import { defineFunction } from '@aws-amplify/backend'; -export const myFunc = Func.fromDir({ - name: 'testFunc', - codePath: './func-src', +export const myFunc = defineFunction({ + entry: './func-src/handler.js', }); diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json index 6e19bd01a9..d785da1235 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json @@ -391,10 +391,10 @@ "Type": "AWS::CloudFormation::Stack", "Properties": { "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Fn::GetAtt": [ "function1351588B", - "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" ] } }, @@ -414,7 +414,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/87aeaefe934ca0965957f8dd07a34567bd92cabf3305a2f27bf7d4da171a7b6f.json" + "/601efeefc2f118029b329879a8fe6e995a9c76c75e5ee99588f1b68113b5436f.json" ] ] } @@ -441,7 +441,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/fffd6fccba429f67fbf54e07b891ec22c20a81177a051793869310e6e94b2a73.json" + "/88b7b9e3302285f902b495ec40076afd46e24597fd162e22388db86e33f56c22.json" ] ] } @@ -504,16 +504,16 @@ "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthIdentityPool7404D50ERef" ] }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Fn::GetAtt": [ "function1351588B", - "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" ] }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Fn::GetAtt": [ "function1351588B", - "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" ] } }, @@ -533,7 +533,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/297077e3e6a1808350dfa1c8959f7f7335d51bd57c6bfbccc629f3ddb2e57d7b.json" + "/38d65f8333e6b54dd31e1d08c25bfacf5d46103d4d3968f5cc433339bb5213a3.json" ] ] } diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json index 81f31dbdab..100298eab8 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json @@ -316,7 +316,7 @@ "EmailVerificationSubject": "Verify your new account", "LambdaConfig": { "PostConfirmation": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" } }, "Policies": { @@ -362,7 +362,7 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" }, "Principal": "cognito-idp.amazonaws.com", "SourceArn": { @@ -644,7 +644,7 @@ } }, "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Type": "String" } }, diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json index 707307fd1a..729291545d 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json @@ -163,8 +163,8 @@ "Type": "AWS::CloudFormation::Stack", "Properties": { "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" }, "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataGraphQLAPI8E80FACEApiId": { "Fn::GetAtt": [ @@ -178,8 +178,8 @@ "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854aauthNestedStackauthNestedStackResource462F2942OutputsamplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthunauthenticatedUserRoleF922AD28Ref": { "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854aauthNestedStackauthNestedStackResource462F2942OutputsamplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthunauthenticatedUserRoleF922AD28Ref" }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" } }, "TemplateURL": { @@ -198,7 +198,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/390aa9db25a635decfe8354f0dd4e83f6cfe506d71adfd3998181733a678ed01.json" + "/0848bc21a07a9344b4254cf3c2499684d7ae926068bb57f946e7ce996d0e4d0b.json" ] ] } @@ -606,10 +606,10 @@ "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854aauthNestedStackauthNestedStackResource462F2942OutputsamplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthIdentityPool7404D50ERef": { "Type": "String" }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Type": "String" }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Type": "String" } }, diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json index 581f089885..15e925d2cc 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json @@ -41,14 +41,14 @@ "Effect": "Allow", "Resource": [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" }, { "Fn::Join": [ "", [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" }, ":*" ] @@ -75,7 +75,7 @@ }, "LambdaConfig": { "LambdaFunctionArn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn" } }, "Name": "ReverseLambdaDataSource", @@ -188,14 +188,14 @@ "Effect": "Allow", "Resource": [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" }, { "Fn::Join": [ "", [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" }, ":*" ] @@ -222,7 +222,7 @@ }, "LambdaConfig": { "LambdaFunctionArn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" } }, "Name": "EchoLambdaDataSource", @@ -310,7 +310,7 @@ } }, "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Type": "String" }, "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataGraphQLAPI8E80FACEApiId": { @@ -322,7 +322,7 @@ "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854aauthNestedStackauthNestedStackResource462F2942OutputsamplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthunauthenticatedUserRoleF922AD28Ref": { "Type": "String" }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Type": "String" } } diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json index efecf44653..029b8d1a5e 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json @@ -1,7 +1,6 @@ { - "Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"AmplifyPipelineDeploy\",\"createdWith\":\"0.2.1\",\"stackType\":\"function-Lambda\",\"metadata\":{}}", "Resources": { - "testFunctestFuncLambdaFunctionServiceRole09E19D41": { + "handlerlambdaServiceRole46D7AF61": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -32,29 +31,34 @@ ] } }, - "testFunctestFuncLambdaFunction419C520E": { + "handlerlambdaE29D1580": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "S3Key": "efe12e580179d925ecc56ede6195533f23db3a8e887169b63ecb5cc644193f2b.zip" + "S3Key": "ce20b1bbd042ee1db4251e55e10f01aad7d6d5d39a0303451585952ce49958db.zip" + }, + "Environment": { + "Variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "testFunctestFuncLambdaFunctionServiceRole09E19D41", + "handlerlambdaServiceRole46D7AF61", "Arn" ] }, - "Runtime": "nodejs18.x" + "Runtime": "nodejs16.x" }, "DependsOn": [ - "testFunctestFuncLambdaFunctionServiceRole09E19D41" + "handlerlambdaServiceRole46D7AF61" ] }, - "echoFuncechoFuncLambdaFunctionServiceRoleE30E6459": { + "echoFunclambdaServiceRoleF37965D7": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -85,42 +89,47 @@ ] } }, - "echoFuncechoFuncLambdaFunction08680056": { + "echoFunclambdaE17DCA46": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "S3Key": "efe12e580179d925ecc56ede6195533f23db3a8e887169b63ecb5cc644193f2b.zip" + "S3Key": "fee8578fcf3b0063089a4abe381e26050b959e96c277ed3b554fd6515fa84151.zip" + }, + "Environment": { + "Variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "echoFuncechoFuncLambdaFunctionServiceRoleE30E6459", + "echoFunclambdaServiceRoleF37965D7", "Arn" ] }, - "Runtime": "nodejs18.x" + "Runtime": "nodejs16.x" }, "DependsOn": [ - "echoFuncechoFuncLambdaFunctionServiceRoleE30E6459" + "echoFunclambdaServiceRoleF37965D7" ] } }, "Outputs": { - "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionhandlerlambda640CAA5DArn": { "Value": { "Fn::GetAtt": [ - "testFunctestFuncLambdaFunction419C520E", + "handlerlambdaE29D1580", "Arn" ] } }, - "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Value": { "Fn::GetAtt": [ - "echoFuncechoFuncLambdaFunction08680056", + "echoFunclambdaE17DCA46", "Arn" ] } diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/update-1/data/resource.ts b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/update-1/data/resource.ts index c89ae4cc0e..a6ef53f3a6 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/update-1/data/resource.ts +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-js/update-1/data/resource.ts @@ -1,4 +1,4 @@ -import { defineData } from '@aws-amplify/backend-graphql'; +import { defineData } from '@aws-amplify/backend'; const schema = ` input AMPLIFY {globalAuthRule: AuthRule = { allow: public }} # FOR TESTING ONLY! diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/echo/handler.ts b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/echo/handler.ts new file mode 100644 index 0000000000..a74409aa20 --- /dev/null +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/echo/handler.ts @@ -0,0 +1,6 @@ +/** + * Hello world lambda used for testing + */ +export const handler = async () => { + return 'hello world lambda'; +}; diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/echo/mock.txt b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/echo/mock.txt deleted file mode 100644 index 5e253db13e..0000000000 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/echo/mock.txt +++ /dev/null @@ -1,2 +0,0 @@ -To test out creating a lambda we need a directory that simulates the lambda content. -Obviously this is not a real lambda, but it allows CDK synth to proceed. diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/resource.ts b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/resource.ts index 9fb6b3e1f7..d0edc17f27 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/resource.ts +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/data/resource.ts @@ -1,5 +1,10 @@ import { myFunc } from '../function.js'; -import { type ClientSchema, Func, a, defineData } from '@aws-amplify/backend'; +import { + type ClientSchema, + a, + defineData, + defineFunction, +} from '@aws-amplify/backend'; const schema = a.schema({ Todo: a @@ -38,9 +43,9 @@ export const data = defineData({ reverse: myFunc, // Leaving explicit Func invocation here, // ensuring we can use functions not added to `defineBackend`. - echo: Func.fromDir({ + echo: defineFunction({ name: 'echoFunc', - codePath: './echo', + entry: './echo/handler.ts', }), }, }); diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/handler.ts b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/handler.ts new file mode 100644 index 0000000000..5af50164c1 --- /dev/null +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/handler.ts @@ -0,0 +1,6 @@ +import { getResponse } from './response_generator.js'; + +/** + * Dummy lambda handler to test building a function with a local import + */ +export const handler = async () => getResponse(); diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/mock.txt b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/mock.txt deleted file mode 100644 index 29cc220aee..0000000000 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/mock.txt +++ /dev/null @@ -1,2 +0,0 @@ -To test out creating a lambda we need a directory that simulates the lambda content. -Obviously this is not a real lambda, but it allows CDK synth to proceed. diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/response_generator.ts b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/response_generator.ts new file mode 100644 index 0000000000..d4aa7c8816 --- /dev/null +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/func-src/response_generator.ts @@ -0,0 +1,14 @@ +import { stringify as uuidStringify } from 'uuid'; + +/** + * Dummy function to test building a lambda that has a 3P import + */ +export const getResponse = () => { + // create a deterministic uuid + const uuidBytes = [ + 0x6e, 0xc0, 0xbd, 0x7f, 0x11, 0xc0, 0x43, 0xda, 0x97, 0x5e, 0x2a, 0x8a, + 0xd9, 0xeb, 0xae, 0x0b, + ]; + // eslint-disable-next-line spellcheck/spell-checker + return `Your uuid is ${uuidStringify(uuidBytes)}`; // '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b' +}; diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/function.ts b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/function.ts index ea270c6747..dfc2ef586e 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/function.ts +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/amplify/function.ts @@ -1,6 +1,6 @@ -import { Func } from '@aws-amplify/backend'; +import { defineFunction } from '@aws-amplify/backend'; -export const myFunc = Func.fromDir({ - name: 'testFunc', - codePath: './func-src', +export const myFunc = defineFunction({ + name: 'specialTestFunction', + entry: './func-src/handler.ts', }); diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json index baf16dba0e..3364a5b675 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json @@ -400,10 +400,10 @@ "Type": "AWS::CloudFormation::Stack", "Properties": { "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionspecialTestFunctionlambda0688CD5DArn": { "Fn::GetAtt": [ "function1351588B", - "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionspecialTestFunctionlambda0688CD5DArn" ] } }, @@ -423,7 +423,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/87aeaefe934ca0965957f8dd07a34567bd92cabf3305a2f27bf7d4da171a7b6f.json" + "/9f71e49e8d317f7bf49b5734f898c8697fd3b5210bf862d6e52cfde157b965c4.json" ] ] } @@ -450,7 +450,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/fffd6fccba429f67fbf54e07b891ec22c20a81177a051793869310e6e94b2a73.json" + "/9c68b83eec1055821272eb84581a1d4ed9f5c18f5618be403beca9c6a445f1b1.json" ] ] } @@ -513,10 +513,10 @@ "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthIdentityPool7404D50ERef" ] }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Fn::GetAtt": [ "function1351588B", - "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" ] } }, @@ -536,7 +536,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/a2923c8e0151bf1cc187b890c02128997bb14abb8009bda4e67e9771b0e30c7a.json" + "/40583c2982a9c1e19dbe32ad7ed34dd47363d6ccf2f5f42f55a12dddd590d2a4.json" ] ] } diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json index 81f31dbdab..f7628d4cdd 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854aauth473E022C.nested.template.json @@ -316,7 +316,7 @@ "EmailVerificationSubject": "Verify your new account", "LambdaConfig": { "PostConfirmation": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionspecialTestFunctionlambda0688CD5DArn" } }, "Policies": { @@ -362,7 +362,7 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionspecialTestFunctionlambda0688CD5DArn" }, "Principal": "cognito-idp.amazonaws.com", "SourceArn": { @@ -644,7 +644,7 @@ } }, "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionspecialTestFunctionlambda0688CD5DArn": { "Type": "String" } }, diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json index aad5172e57..5827a8292f 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json @@ -47,7 +47,7 @@ "ApiId" ] }, - "Expires": 1703801364 + "Expires": 1703878639 } }, "amplifyDataGraphQLAPINONEDS684BF699": { @@ -176,8 +176,8 @@ "Type": "AWS::CloudFormation::Stack", "Properties": { "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" }, "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataGraphQLAPI8E80FACEApiId": { "Fn::GetAtt": [ @@ -214,7 +214,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/26f20f3fc00373eb0d67d7c89d1f8dda3f8bebbb3e1550d70bd6d126da6d6730.json" + "/313ef813581ce8a50e6465ec2bcbf54abdeeb5fa9a6b2b43d7c11b6989adeb41.json" ] ] } @@ -622,7 +622,7 @@ "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854aauthNestedStackauthNestedStackResource462F2942OutputsamplifytestAppIdtestBranchNamebranch7d6f6c854aauthamplifyAuthIdentityPool7404D50ERef": { "Type": "String" }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Type": "String" } }, diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json index 7a431ffe39..a841c1bdda 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataFunctionDirectiveStack93F75775.nested.template.json @@ -41,14 +41,14 @@ "Effect": "Allow", "Resource": [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" }, { "Fn::Join": [ "", [ { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" }, ":*" ] @@ -75,7 +75,7 @@ }, "LambdaConfig": { "LambdaFunctionArn": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn" } }, "Name": "EchoLambdaDataSource", @@ -186,7 +186,7 @@ } }, "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Type": "String" }, "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854adataamplifyDataGraphQLAPI8E80FACEApiId": { diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json index efecf44653..0677184e6c 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json @@ -1,7 +1,6 @@ { - "Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"AmplifyPipelineDeploy\",\"createdWith\":\"0.2.1\",\"stackType\":\"function-Lambda\",\"metadata\":{}}", "Resources": { - "testFunctestFuncLambdaFunctionServiceRole09E19D41": { + "specialTestFunctionlambdaServiceRole0C3D972B": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -32,29 +31,34 @@ ] } }, - "testFunctestFuncLambdaFunction419C520E": { + "specialTestFunctionlambda1BF9BBA4": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "S3Key": "efe12e580179d925ecc56ede6195533f23db3a8e887169b63ecb5cc644193f2b.zip" + "S3Key": "d734d72b26bbfcea4362172e7e5076e26ab1859f5e1dffaee893424e20dcb690.zip" + }, + "Environment": { + "Variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "testFunctestFuncLambdaFunctionServiceRole09E19D41", + "specialTestFunctionlambdaServiceRole0C3D972B", "Arn" ] }, - "Runtime": "nodejs18.x" + "Runtime": "nodejs16.x" }, "DependsOn": [ - "testFunctestFuncLambdaFunctionServiceRole09E19D41" + "specialTestFunctionlambdaServiceRole0C3D972B" ] }, - "echoFuncechoFuncLambdaFunctionServiceRoleE30E6459": { + "echoFunclambdaServiceRoleF37965D7": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -85,42 +89,47 @@ ] } }, - "echoFuncechoFuncLambdaFunction08680056": { + "echoFunclambdaE17DCA46": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "S3Key": "efe12e580179d925ecc56ede6195533f23db3a8e887169b63ecb5cc644193f2b.zip" + "S3Key": "8ec7c45f429a0cbe47336d1e8f7cd0efae9cd53d7597f14aa180fa922b5be180.zip" + }, + "Environment": { + "Variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "echoFuncechoFuncLambdaFunctionServiceRoleE30E6459", + "echoFunclambdaServiceRoleF37965D7", "Arn" ] }, - "Runtime": "nodejs18.x" + "Runtime": "nodejs16.x" }, "DependsOn": [ - "echoFuncechoFuncLambdaFunctionServiceRoleE30E6459" + "echoFunclambdaServiceRoleF37965D7" ] } }, "Outputs": { - "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctiontestFunctestFuncLambdaFunction675DD8C2Arn": { + "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionspecialTestFunctionlambda0688CD5DArn": { "Value": { "Fn::GetAtt": [ - "testFunctestFuncLambdaFunction419C520E", + "specialTestFunctionlambda1BF9BBA4", "Arn" ] } }, - "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFuncechoFuncLambdaFunctionCC7FF4D5Arn": { + "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionechoFunclambda1F2D9982Arn": { "Value": { "Fn::GetAtt": [ - "echoFuncechoFuncLambdaFunction08680056", + "echoFunclambdaE17DCA46", "Arn" ] } diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/update-1/data/resource.ts b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/update-1/data/resource.ts index 6cf24f1855..ea8523c5f4 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/update-1/data/resource.ts +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/update-1/data/resource.ts @@ -1,5 +1,10 @@ import { myFunc } from '../function.js'; -import { type ClientSchema, Func, a, defineData } from '@aws-amplify/backend'; +import { + type ClientSchema, + a, + defineData, + defineFunction, +} from '@aws-amplify/backend'; const schema = a.schema({ Todo: a @@ -38,9 +43,9 @@ export const data = defineData({ reverse: myFunc, // Leaving explicit Func invocation here, // ensuring we can use functions not added to `defineBackend`. - echo: Func.fromDir({ + echo: defineFunction({ name: 'echoFunc', - codePath: './echo', + entry: './echo/handler.ts', }), }, }); diff --git a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/update-1/function.ts b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/update-1/function.ts index ea270c6747..6a43bdbc65 100644 --- a/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/update-1/function.ts +++ b/packages/integration-tests/test-projects/data-storage-auth-with-triggers-ts/update-1/function.ts @@ -1,6 +1,5 @@ -import { Func } from '@aws-amplify/backend'; +import { defineFunction } from '@aws-amplify/backend'; -export const myFunc = Func.fromDir({ - name: 'testFunc', - codePath: './func-src', +export const myFunc = defineFunction({ + entry: './func-src/handler.ts', }); diff --git a/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/api-auth/mock.txt b/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/api-auth/mock.txt deleted file mode 100644 index 29cc220aee..0000000000 --- a/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/api-auth/mock.txt +++ /dev/null @@ -1,2 +0,0 @@ -To test out creating a lambda we need a directory that simulates the lambda content. -Obviously this is not a real lambda, but it allows CDK synth to proceed. diff --git a/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/lambda_authorizer.ts b/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/lambda_authorizer.ts new file mode 100644 index 0000000000..a74409aa20 --- /dev/null +++ b/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/lambda_authorizer.ts @@ -0,0 +1,6 @@ +/** + * Hello world lambda used for testing + */ +export const handler = async () => { + return 'hello world lambda'; +}; diff --git a/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/resource.ts b/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/resource.ts index 4a239517be..1adc7c73cc 100644 --- a/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/resource.ts +++ b/packages/integration-tests/test-projects/standalone-data-auth-modes/amplify/data/resource.ts @@ -1,4 +1,4 @@ -import { Func, defineData } from '@aws-amplify/backend'; +import { defineData, defineFunction } from '@aws-amplify/backend'; export const data = defineData({ schema: /* GraphQL */ ` @@ -17,9 +17,9 @@ export const data = defineData({ authorizationModes: { defaultAuthorizationMode: 'lambda', lambdaAuthorizationMode: { - function: Func.fromDir({ - name: 'ApiAuth', - codePath: 'api-auth', + function: defineFunction({ + // eslint-disable-next-line spellcheck/spell-checker + entry: './lambda_authorizer.ts', }), timeToLiveInSeconds: 0, }, diff --git a/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json b/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json index 0661090f1d..dbee98032a 100644 --- a/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json +++ b/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json @@ -295,10 +295,10 @@ "Type": "AWS::CloudFormation::Stack", "Properties": { "Parameters": { - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionApiAuthApiAuthLambdaFunctionCFF4ED65Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionlambdaauthorizerlambdaD2057200Arn": { "Fn::GetAtt": [ "function1351588B", - "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionApiAuthApiAuthLambdaFunctionCFF4ED65Arn" + "Outputs.amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionlambdaauthorizerlambdaD2057200Arn" ] } }, @@ -318,7 +318,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/bbfa2151094c52f731c7da6f41f42b9fdbcffa26d8ab0aeb796923c8ad92e36f.json" + "/d25f871ae362f56389c1ccda0b350546833da108ef4cfc6d416b6e56a20448c2.json" ] ] } @@ -345,7 +345,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/ff5f3459e2a88acce35d48501a8ec5378392604dbba56363c8c4153e4568f1f0.json" + "/36a67e80be9b6f698e1b433195eb1b7a8214ca85775562e0f9bffdf3f1b0b358.json" ] ] } diff --git a/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json b/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json index fe64256218..18a8db87cf 100644 --- a/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json +++ b/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json @@ -21,7 +21,7 @@ "LambdaAuthorizerConfig": { "AuthorizerResultTtlInSeconds": 0, "AuthorizerUri": { - "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionApiAuthApiAuthLambdaFunctionCFF4ED65Arn" + "Ref": "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionlambdaauthorizerlambdaD2057200Arn" }, "IdentityValidationExpression": "" }, @@ -51,7 +51,7 @@ "ApiId" ] }, - "Expires": 1703801366 + "Expires": 1703878640 } }, "amplifyDataGraphQLAPINONEDS684BF699": { @@ -553,7 +553,7 @@ ], "Description": "Enable server side encryption powered by KMS." }, - "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionApiAuthApiAuthLambdaFunctionCFF4ED65Arn": { + "referencetoamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionNestedStackfunctionNestedStackResource482C479FOutputsamplifytestAppIdtestBranchNamebranch7d6f6c854afunctionlambdaauthorizerlambdaD2057200Arn": { "Type": "String" } }, diff --git a/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json b/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json index 6574a65285..44d95bec23 100644 --- a/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json +++ b/packages/integration-tests/test-projects/standalone-data-auth-modes/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionDE2842E0.nested.template.json @@ -1,7 +1,6 @@ { - "Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"AmplifyPipelineDeploy\",\"createdWith\":\"0.2.1\",\"stackType\":\"function-Lambda\",\"metadata\":{}}", "Resources": { - "ApiAuthApiAuthLambdaFunctionServiceRole568E246E": { + "lambdaauthorizerlambdaServiceRoleCF35E55A": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -32,35 +31,40 @@ ] } }, - "ApiAuthApiAuthLambdaFunctionF84061EE": { + "lambdaauthorizerlambda4ACE2410": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "S3Key": "efe12e580179d925ecc56ede6195533f23db3a8e887169b63ecb5cc644193f2b.zip" + "S3Key": "4a66b7e5d6972e7f007f7b05bc1120abeebb6878a29ee6071a79eac87896494d.zip" + }, + "Environment": { + "Variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "ApiAuthApiAuthLambdaFunctionServiceRole568E246E", + "lambdaauthorizerlambdaServiceRoleCF35E55A", "Arn" ] }, - "Runtime": "nodejs18.x" + "Runtime": "nodejs16.x" }, "DependsOn": [ - "ApiAuthApiAuthLambdaFunctionServiceRole568E246E" + "lambdaauthorizerlambdaServiceRoleCF35E55A" ] }, - "ApiAuthApiAuthLambdaFunctionappsyncauthinvokeC187D22A": { + "lambdaauthorizerlambdaappsyncauthinvoke93C85899": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "ApiAuthApiAuthLambdaFunctionF84061EE", + "lambdaauthorizerlambda4ACE2410", "Arn" ] }, @@ -69,10 +73,10 @@ } }, "Outputs": { - "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionApiAuthApiAuthLambdaFunctionCFF4ED65Arn": { + "amplifytestAppIdtestBranchNamebranch7d6f6c854afunctionlambdaauthorizerlambdaD2057200Arn": { "Value": { "Fn::GetAtt": [ - "ApiAuthApiAuthLambdaFunctionF84061EE", + "lambdaauthorizerlambda4ACE2410", "Arn" ] } diff --git a/packages/integration-tests/test-projects/standalone-data-sandbox-mode/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json b/packages/integration-tests/test-projects/standalone-data-sandbox-mode/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json index eeec0340bf..8726bd8f1c 100644 --- a/packages/integration-tests/test-projects/standalone-data-sandbox-mode/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json +++ b/packages/integration-tests/test-projects/standalone-data-sandbox-mode/expected-cdk-out/amplify-testAppId-testBranchName-branch-7d6f6c854a.template.json @@ -306,7 +306,7 @@ { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" }, - "/17fc8d4466f74a8e2f3102e03c106d049ee22a25d86a9d47406f287011246496.json" + "/5b3b700c10856197bf0f6f3048792cdc9a2a5835c1f3e1092b73ae46fd39ae4d.json" ] ] } diff --git a/packages/integration-tests/test-projects/standalone-data-sandbox-mode/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json b/packages/integration-tests/test-projects/standalone-data-sandbox-mode/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json index 0d3afa7817..380f1178d2 100644 --- a/packages/integration-tests/test-projects/standalone-data-sandbox-mode/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json +++ b/packages/integration-tests/test-projects/standalone-data-sandbox-mode/expected-cdk-out/amplifytestAppIdtestBranchNamebranch7d6f6c854adataE67321C2.nested.template.json @@ -31,7 +31,7 @@ "ApiId" ] }, - "Expires": 1701814168 + "Expires": 1701891441 } }, "amplifyDataGraphQLAPINONEDS684BF699": { diff --git a/packages/plugin-types/API.md b/packages/plugin-types/API.md index 743398be43..8b5e78025d 100644 --- a/packages/plugin-types/API.md +++ b/packages/plugin-types/API.md @@ -9,7 +9,7 @@ import { CfnIdentityPoolRoleAttachment } from 'aws-cdk-lib/aws-cognito'; import { CfnUserPool } from 'aws-cdk-lib/aws-cognito'; import { CfnUserPoolClient } from 'aws-cdk-lib/aws-cognito'; import { Construct } from 'constructs'; -import { Function as Function_2 } from 'aws-cdk-lib/aws-lambda'; +import { IFunction } from 'aws-cdk-lib/aws-lambda'; import { IRole } from 'aws-cdk-lib/aws-iam'; import { IUserPool } from 'aws-cdk-lib/aws-cognito'; import { IUserPoolClient } from 'aws-cdk-lib/aws-cognito'; @@ -115,7 +115,7 @@ export type DeploymentType = 'branch' | 'sandbox'; // @public (undocumented) export type FunctionResources = { - lambda: Function_2; + lambda: IFunction; }; // @public diff --git a/packages/plugin-types/src/function_resources.ts b/packages/plugin-types/src/function_resources.ts index 8e70d13a35..8734c04ee9 100644 --- a/packages/plugin-types/src/function_resources.ts +++ b/packages/plugin-types/src/function_resources.ts @@ -1,5 +1,5 @@ -import { Function as LambdaFunction } from 'aws-cdk-lib/aws-lambda'; +import { IFunction } from 'aws-cdk-lib/aws-lambda'; export type FunctionResources = { - lambda: LambdaFunction; + lambda: IFunction; };