aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.44k stars 2.13k forks source link

Property 'multiOwner' is missing in type 'ResourceAuthorizationData' when using a.allow.resource(functionWithDataAccess) as authorization #13202

Closed gpavlov2016 closed 7 months ago

gpavlov2016 commented 8 months ago

Before opening, please confirm:

JavaScript Framework

Next.js

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

function

Backend

Amplify Gen 2 (Preview)

Environment information

``` # Put output below this line System: OS: Windows 11 10.0.22631 CPU: (20) x64 13th Gen Intel(R) Core(TM) i9-13900H Memory: 3.52 GB / 31.68 GB Binaries: Node: 18.19.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD pnpm: 8.15.4 - ~\AppData\Local\pnpm\pnpm.EXE Browsers: Edge: Chromium (122.0.2365.92) Internet Explorer: 11.0.22621.1 npmPackages: %name%: 0.1.0 @ampproject/toolbox-optimizer: undefined () @aws-amplify/backend: ^0.13.0-beta.13 => 0.13.0-beta.13 @aws-amplify/backend-cli: ^0.12.0-beta.15 => 0.12.0-beta.15 @aws-amplify/ui-react: ^6.1.6 => 6.1.6 @aws-amplify/ui-react-internal: undefined () @aws-sdk/client-s3: ^3.540.0 => 3.540.0 @aws-sdk/s3-presigned-post: ^3.540.0 => 3.540.0 @aws-sdk/signature-v4-crt: ^3.535.0 => 3.535.0 @babel/core: undefined () @babel/runtime: 7.22.5 @edge-runtime/cookies: 4.1.0 @edge-runtime/ponyfill: 2.4.2 @edge-runtime/primitives: 4.1.0 @hapi/accept: undefined () @heroicons/react: ^1.0.6 => 1.0.6 @mswjs/interceptors: undefined () @napi-rs/triples: undefined () @next/font: undefined () @next/react-dev-overlay: undefined () @opentelemetry/api: undefined () @types/node: ^20 => 20.11.30 @types/react: ^18 => 18.2.73 @types/react-dom: ^18 => 18.2.23 @vercel/nft: undefined () @vercel/og: 0.6.2 acorn: undefined () amphtml-validator: undefined () anser: undefined () arg: undefined () assert: undefined () async-retry: undefined () async-sema: undefined () autoprefixer: ^10.4.19 => 10.4.19 aws-amplify: ^6.0.24 => 6.0.24 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/enable-oauth-listener: undefined () aws-amplify/auth/server: undefined () aws-amplify/data: undefined () aws-amplify/data/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () aws-cdk: ^2.134.0 => 2.134.0 aws-cdk-lib: ^2.134.0 => 2.134.0 babel-packages: undefined () browserify-zlib: undefined () browserslist: undefined () buffer: undefined () bytes: undefined () ci-info: undefined () cli-select: undefined () client-only: 0.0.1 comment-json: undefined () compression: undefined () conf: undefined () constants-browserify: undefined () constructs: ^10.3.0 => 10.3.0 content-disposition: undefined () content-type: undefined () cookie: undefined () cross-spawn: undefined () crypto-browserify: undefined () css.escape: undefined () data-uri-to-buffer: undefined () debug: undefined () devalue: undefined () domain-browser: undefined () edge-runtime: undefined () esbuild: ^0.20.2 => 0.20.2 (0.19.12) eslint: ^8 => 8.57.0 eslint-config-next: 14.1.4 => 14.1.4 events: undefined () find-cache-dir: undefined () find-up: undefined () fresh: undefined () get-orientation: undefined () glob: undefined () gzip-size: undefined () http-proxy: undefined () http-proxy-agent: undefined () https-browserify: undefined () https-proxy-agent: undefined () icss-utils: undefined () ignore-loader: undefined () image-size: undefined () is-animated: undefined () is-docker: undefined () is-wsl: undefined () jest-worker: undefined () json5: undefined () jsonwebtoken: undefined () loader-runner: undefined () loader-utils: undefined () lodash.curry: undefined () lru-cache: undefined () micromatch: undefined () mini-css-extract-plugin: undefined () nanoid: undefined () native-url: undefined () neo-async: undefined () next: 14.1.4 => 14.1.4 node-fetch: undefined () node-html-parser: undefined () ora: undefined () os-browserify: undefined () p-limit: undefined () path-browserify: undefined () platform: undefined () postcss: ^8.4.38 => 8.4.38 (8.4.31) postcss-flexbugs-fixes: undefined () postcss-modules-extract-imports: undefined () postcss-modules-local-by-default: undefined () postcss-modules-scope: undefined () postcss-modules-values: undefined () postcss-preset-env: undefined () postcss-safe-parser: undefined () postcss-scss: undefined () postcss-value-parser: undefined () process: undefined () punycode: undefined () querystring-es3: undefined () raw-body: undefined () react: ^18 => 18.2.0 react-builtin: undefined () react-dom: ^18 => 18.2.0 react-dom-builtin: undefined () react-dom-experimental-builtin: undefined () react-experimental-builtin: undefined () react-is: 18.2.0 react-refresh: 0.12.0 react-server-dom-turbopack-builtin: undefined () react-server-dom-turbopack-experimental-builtin: undefined () react-server-dom-webpack-builtin: undefined () react-server-dom-webpack-experimental-builtin: undefined () regenerator-runtime: 0.13.4 sass-loader: undefined () scheduler-builtin: undefined () scheduler-experimental-builtin: undefined () schema-utils: undefined () semver: undefined () send: undefined () server-only: 0.0.1 setimmediate: undefined () shell-quote: undefined () source-map: undefined () stacktrace-parser: undefined () stream-browserify: undefined () stream-http: undefined () string-hash: undefined () string_decoder: undefined () strip-ansi: undefined () superstruct: undefined () tailwindcss: ^3.4.3 => 3.4.3 tar: undefined () terser: undefined () text-table: undefined () timers-browserify: undefined () tsx: ^4.7.1 => 4.7.1 tty-browserify: undefined () typescript: ^5.4.3 => 5.4.3 (4.4.4, 4.9.5) ua-parser-js: undefined () unistore: undefined () util: undefined () vm-browserify: undefined () watchpack: undefined () web-vitals: undefined () webpack: undefined () webpack-sources: undefined () ws: undefined () zod: undefined () npmGlobalPackages: @aws-amplify/cli: 12.10.3 corepack: 0.22.0 npm: 10.2.4 ```

Describe the bug

Error message when defining resource authorization on a model schema in amplify\data\resource.ts

const functionWithDataAccess = defineFunction({
  entry: '../functions/update-playlists/handler.ts',
});
const schema = a.schema({
  Video: a
    .model({
      title: a.string(),
      timeOfDayStart: a.time(),
      timeOfDayEnd: a.time(),
      dateStart: a.date(),
      dateEnd: a.date(),
      impressionsTarget: a.integer(),
      zipCode: a.string(),
      s3Key: a.string(),
      thumbnail: a.string(),
      isRunning: a.boolean(),
    })
    .authorization([
      a.allow.owner(), 
      a.allow.resource(functionWithDataAccess),
    ]),
});

Error message:

Type 'ResourceAuthorization & { to: (this: SELF, operations: ("listen" | "query" | "mutate")[]) => Omit<SELF, "to">; }' is not assignable to type 'Authorization<any, any, any>'. Types of property '[__data]' are incompatible. Property 'multiOwner' is missing in type 'ResourceAuthorizationData' but required in type '{ strategy?: any; provider?: "function" | "apiKey" | "iam" | "userPools" | "oidc" | undefined; operations?: ("create" | "update" | "delete" | "read" | "get" | "list" | "sync" | "listen" | "search")[] | undefined; ... 4 more ...; groupClaim?: string | undefined; }'.ts(2322) Authorization.d.ts(68, 9): 'multiOwner' is declared here.

Expected behavior

Per the tutorial here it should work

Reproduction steps

Follow the tutorial here

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

chrisbonifacio commented 8 months ago

Hey @gpavlov2016 thanks for raising this issue and providing reproduction steps. We will reproduce this internally and provide an update soon.

chrisbonifacio commented 7 months ago

I was able to reproduce the issue but it seems to be expected behavior. The a.allow.resource method is expected to be used on the schema level rather than the model level to grant a resource, in this case a lambda function, permission to perform Query, Mutation, and Subscription operations against the GraphQL API.

You can correct your schema code to this and it should work:

const schema = a
  .schema({
    Video: a
      .model({
        title: a.string(),
        timeOfDayStart: a.time(),
        timeOfDayEnd: a.time(),
        dateStart: a.date(),
        dateEnd: a.date(),
        impressionsTarget: a.integer(),
        zipCode: a.string(),
        s3Key: a.string(),
        thumbnail: a.string(),
        isRunning: a.boolean(),
      })
      .authorization([a.allow.owner()]),
  })
  .authorization([a.allow.resource(functionWithDataAccess)]);

Let me know if this unblocks you or if you run into an issue with this example as well

chrisbonifacio commented 7 months ago

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!

gpavlov2016 commented 7 months ago

Applying the authorization to the schema as suggested does remove the type error however it results in a new error during deployment of the sandbox as follows:

const schema = a
  .schema({
    Video: a
      .model({
        title: a.string(),
        timeOfDayStart: a.time(),
        timeOfDayEnd: a.time(),
        dateStart: a.date(),
        dateEnd: a.date(),
        impressionsTarget: a.integer(),
        zipCode: a.string(),
        s3Key: a.string(),
        thumbnail: a.string(),
        isRunning: a.boolean(),
      })
      .authorization([a.allow.owner()]),
  })
  .authorization([a.allow.resource(getPresignedUrl)]);

Error:

[

[Sandbox] Detected file changes while previous deployment was in progress. Invoking 'sandbox' again

Error: WARNING: owners may reassign ownership for the following model(s) and role(s): Video: [owner]. If this is not intentional, you may want to apply field-level authorization rules to these fields. To read more: https://docs.amplify.aws/cli/graphql/authorization-rules/#per-user--owner-based-data-access. Bundling asset amplify-nextamplifygen2-GuyPavlov-sandbox-5763ff2c4a/function/presigned-url-lambda/Code/Stage... X [ERROR] Must use "outdir" when there are multiple input files

1 error node:child_process:929 throw err; ^

Error: Command failed: C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\@esbuild\win32-x64\esbuild.exe --bundle C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\amplify\functions\presigned-url\handler.ts --target=node18 --platform=node --format=esm --outfile=C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal.amplify\artifacts\cdk.out\bundling-temp-e9230d152b0810080159375cfbc0a4ef95e64e8e4cd66a766f288da9cc5dba82\index.mjs --external:@aws-sdk/* --loader:.node=file --banner:js=/* This code loads environment values from SSM and places them in their corresponding environment variables. If there are no SSM environment values for this function, this is a noop. /import { SSM } from '@aws-sdk/client-ssm';/* Reads SSM environment context from a known Amplify environment variable, fetches values from SSM and places those values in the corresponding environment variables /export const internalAmplifyFunctionResolveSsmParams = async (client = new SSM()) => { const envPathObject = JSON.parse(process.env.AMPLIFY_SSM_ENV_CONFIG ?? '{}'); const paths = Object.keys(envPathObject); if (paths.length === 0) { return; } const resolveSecrets = async (paths) => { const response = await client.getParameters({ Names: paths, WithDecryption: true, }); if (response.Parameters && response.Parameters.length > 0) { for (const parameter of response.Parameters) { if (parameter.Name) { const envKey = Object.keys(envPathObject).find((key) => envPathObject[key].sharedPath === parameter.Name); const envName = envKey ? envPathObject[envKey].name : envPathObject[parameter.Name]?.name; process.env[envName] = parameter.Value; } } } return response; }; const response = await resolveSecrets(paths); const sharedPaths = (response?.InvalidParameters || []) .map((invalidParam) => envPathObject[invalidParam].sharedPath) .filter((sharedParam) => !!sharedParam); if (sharedPaths.length > 0) { await resolveSecrets(sharedPaths); }};await internalAmplifyFunctionResolveSsmParams();const SSM_PARAMETER_REFRESH_MS = 1000 * 60;setInterval(() => { void internalAmplifyFunctionResolveSsmParams();}, SSM_PARAMETER_REFRESH_MS);export {}; --inject:C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\@aws-amplify\backend-function\lib\lambda-shims\cjs_shim.js at checkExecSyncError (node:child_process:890:11) at Object.execFileSync (node:child_process:926:15) at Object. (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\esbuild\bin\esbuild:221:28) at Module._compile (node:internal/modules/cjs/loader:1356:14) at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) at Module.load (node:internal/modules/cjs/loader:1197:32) at Module._load (node:internal/modules/cjs/loader:1013:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) at node:internal/main/run_main_module:28:49 { status: 1, signal: null, output: [ null, null, null ], pid: 34788, stdout: null, stderr: null }

Node.js v18.19.1 C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:2 ),localBundling=options.local?.tryBundle(bundleDir,options),!localBundling){const assetStagingOptions={sourcePath:this.sourcePath,bundleDir,...options};switch(options.bundlingFileAccess){case bundling_1().BundlingFileAccess.VOLUME_COPY:new(asset_staging_1()).AssetBundlingVolumeCopy(assetStagingOptions).run();break;case bundling_1().BundlingFileAccess.BIND_MOUNT:default:new(asset_staging_1()).AssetBundlingBindMount(assetStagingOptions).run();break}}}catch(err){const bundleErrorDir=bundleDir+"-error";throw fs().existsSync(bundleErrorDir)&&fs().removeSync(bundleErrorDir),fs().renameSync(bundleDir,bundleErrorDir),new Error(Failed to bundle asset ${this.node.path}, bundle output is located at ${bundleErrorDir}: ${err})}if(fs_1().FileSystem.isEmpty(bundleDir)){const outputDir=localBundling?bundleDir:AssetStaging.BUNDLING_OUTPUT_DIR;throw new Error(Bundling did not produce any output. Check that content is written to ${outputDir}.)}}calculateHash(hashType,bundling,outputDir){if(hashType==assets_1().AssetHashType.CUSTOM||hashType==assets_1().AssetHashType.SOURCE&&bundling){const hash=crypto().createHash("sha256");return hash.update(this.customSourceFingerprint??fs_1().FileSystem.fingerprint(this.sourcePath,this.fingerprintOptions)),bundling&&hash.update(JSON.stringify(bundling,sanitizeHashValue)),hash.digest("hex")}switch(hashType){case assets_1().AssetHashType.SOURCE:return fs_1().FileSystem.fingerprint(this.sourcePath,this.fingerprintOptions);case assets_1().AssetHashType.BUNDLE:case assets_1().AssetHashType.OUTPUT:if(!outputDir)throw new Error(Cannot use `${hashType}` hash type when `bundling` is not specified.);return fs_1().FileSystem.fingerprint(outputDir,this.fingerprintOptions);default:throw new Error("Unknown asset hash type.")}}}exports.AssetStaging=AssetStaging,_a=JSII_RTTI_SYMBOL_1,AssetStaging[_a]={fqn:"aws-cdk-lib.AssetStaging",version:"2.134.0"},AssetStaging.BUNDLING_INPUT_DIR="/asset-input",AssetStaging.BUNDLING_OUTPUT_DIR="/asset-output",AssetStaging.assetCache=new(cache_1()).Cache;function renderAssetFilename(assetHash,extension=""){returnasset.${assetHash}${extension}}function determineHashType(assetHashType,customSourceFingerprint){const hashType=customSourceFingerprint?assetHashType??assets_1().AssetHashType.CUSTOM:assetHashType??assets_1().AssetHashType.SOURCE;if(customSourceFingerprint&&hashType!==assets_1().AssetHashType.CUSTOM)throw new Error(Cannot specify `${assetHashType}` for `assetHashType` when `assetHash` is specified. Use `CUSTOM` or leave `undefined`.);if(hashType===assets_1().AssetHashType.CUSTOM&&!customSourceFingerprint)throw new Error("assetHashmust be specified whenassetHashTypeis set toAssetHashType.CUSTOM.");return hashType}function calculateCacheKey(props){return crypto().createHash("sha256").update(JSON.stringify(sortObject(props),sanitizeHashValue)).digest("hex")}function sortObject(object){if(typeof object!="object"||object instanceof Array)return object;const ret={};for(const key of Object.keys(object).sort())ret[key]=sortObject(object[key]);return ret}function sanitizeHashValue(key,value){if(key==="PIP_INDEX_URL"||key==="PIP_EXTRA_INDEX_URL")try{let url=new URL(value);if(url.password)return url.password="",url.toString()}catch(e){throw e.name==="TypeError"?new Error(${key} must be a valid URL, got ${value}.):e}return value}function findSingleFile(directory,archiveOnly){if(!fs().existsSync(directory))throw new Error(Directory ${directory} does not exist.);if(!fs().statSync(directory).isDirectory())throw new Error(${directory} is not a directory.);const content=fs().readdirSync(directory);if(content.length===1){const file=path().join(directory,content[0]),extension=getExtension(content[0]).toLowerCase();if(fs().statSync(file).isFile()&&(!archiveOnly||ARCHIVE_EXTENSIONS.includes(extension)))return file}}function determineBundledAsset(bundleDir,outputType){const archiveFile=findSingleFile(bundleDir,outputType!==bundling_1().BundlingOutput.SINGLE_FILE);switch(outputType===bundling_1().BundlingOutput.AUTO_DISCOVER&&(outputType=archiveFile?bundling_1().BundlingOutput.ARCHIVED:bundling_1().BundlingOutput.NOT_ARCHIVED),outputType){case bundling_1().BundlingOutput.NOT_ARCHIVED:return{path:bundleDir,packaging:assets_1().FileAssetPackaging.ZIP_DIRECTORY};case bundling_1().BundlingOutput.ARCHIVED:case bundling_1().BundlingOutput.SINGLE_FILE:if(!archiveFile)throw new Error("Bundling output directory is expected to include only a single file whenoutputis set toARCHIVEDorSINGLE_FILE`");return{path:archiveFile,packaging:assets_1().FileAssetPackaging.FILE,extension:getExtension(archiveFile)}}}function getExtension(source){for(const ext of ARCHIVE_EXTENSIONS)if(source.toLowerCase().endsWith(ext))return ext;return path().extname(source)}

                                                                          ^

Error: Failed to bundle asset amplify-nextamplifygen2-GuyPavlov-sandbox-5763ff2c4a/function/presigned-url-lambda/Code/Stage, bundle output is located at C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal.amplify\artifacts\cdk.out\bundling-temp-e9230d152b0810080159375cfbc0a4ef95e64e8e4cd66a766f288da9cc5dba82-error: Error: cmd /c npx.cmd --no-install esbuild --bundle "C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\amplify\functions\presigned-url\handler.ts" --target=node18 --platform=node --format=esm --outfile="C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal.amplify\artifacts\cdk.out\bundling-temp-e9230d152b0810080159375cfbc0a4ef95e64e8e4cd66a766f288da9cc5dba82\index.mjs" --external:@aws-sdk/* --loader:.node=file --banner:js="/* This code loads environment values from SSM and places them in their corresponding environment variables. If there are no SSM environment values for this function, this is a noop. /import { SSM } from '@aws-sdk/client-ssm';/* Reads SSM environment context from a known Amplify environment variable, fetches values from SSM and places those values in the corresponding environment variables /export const internalAmplifyFunctionResolveSsmParams = async (client = new SSM()) => { const envPathObject = JSON.parse(process.env.AMPLIFY_SSM_ENV_CONFIG ?? '{}'); const paths = Object.keys(envPathObject); if (paths.length === 0) { return; } const resolveSecrets = async (paths) => { const response = await client.getParameters({ Names: paths, WithDecryption: true, }); if (response.Parameters && response.Parameters.length > 0) { for (const parameter of response.Parameters) { if (parameter.Name) {
const envKey = Object.keys(envPathObject).find((key) => envPathObject[key].sharedPath === parameter.Name); const envName = envKey ? envPathObject[envKey].name : envPathObject[parameter.Name]?.name; process.env[envName] = parameter.Value; } } } return response; }; const response = await resolveSecrets(paths); const sharedPaths = (response?.InvalidParameters || []) .map((invalidParam) => envPathObject[invalidParam].sharedPath) .filter((sharedParam) => !!sharedParam); if (sharedPaths.length > 0) { await resolveSecrets(sharedPaths); }};await internalAmplifyFunctionResolveSsmParams();const SSM_PARAMETER_REFRESH_MS = 1000 * 60;setInterval(() => { void internalAmplifyFunctionResolveSsmParams();}, SSM_PARAMETER_REFRESH_MS);export {};" --inject:C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\@aws-amplify\backend-function\lib\lambda-shims\cjs_shim.js run in directory C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal exited with status 1 at AssetStaging.bundle (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:2:619) at AssetStaging.stageByBundling (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:5297) at stageThisAsset (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:2728)
at Cache.obtain (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\private\cache.js:1:242)
at new AssetStaging (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:3125)
at new Asset (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\aws-s3-assets\lib\asset.js:1:1080) at AssetCode.bind (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\aws-lambda\lib\code.js:1:4881)
at new Function (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\aws-lambda\lib\function.js:1:9422)
at new NodejsFunction (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\aws-lambda-nodejs\lib\function.js:1:1669) at AmplifyFunction (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\@aws-amplify\backend-function\src\factory.ts:292:28)

Node.js v18.19.1 Subprocess exited with error 1

Caused By: WARNING: owners may reassign ownership for the following model(s) and role(s): Video: [owner]. If this is not intentional, you may want to apply field-level authorization rules to these fields. To read more: https://docs.amplify.aws/cli/graphql/authorization-rules/#per-user--owner-based-data-access. Bundling asset amplify-nextamplifygen2-GuyPavlov-sandbox-5763ff2c4a/function/presigned-url-lambda/Code/Stage... X [ERROR] Must use "outdir" when there are multiple input files

1 error node:child_process:929 throw err; ^

Error: Command failed: C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\@esbuild\win32-x64\esbuild.exe --bundle C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\amplify\functions\presigned-url\handler.ts --target=node18 --platform=node --format=esm --outfile=C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal.amplify\artifacts\cdk.out\bundling-temp-e9230d152b0810080159375cfbc0a4ef95e64e8e4cd66a766f288da9cc5dba82\index.mjs --external:@aws-sdk/* --loader:.node=file --banner:js=/* This code loads environment values from SSM and places them in their corresponding environment variables. If there are no SSM environment values for this function, this is a noop. /import { SSM } from '@aws-sdk/client-ssm';/* Reads SSM environment context from a known Amplify environment variable, fetches values from SSM and places those values in the corresponding environment variables /export const internalAmplifyFunctionResolveSsmParams = async (client = new SSM()) => { const envPathObject = JSON.parse(process.env.AMPLIFY_SSM_ENV_CONFIG ?? '{}'); const paths = Object.keys(envPathObject); if (paths.length === 0) { return; } const resolveSecrets = async (paths) => { const response = await client.getParameters({ Names: paths, WithDecryption: true, }); if (response.Parameters && response.Parameters.length > 0) { for (const parameter of response.Parameters) { if (parameter.Name) { const envKey = Object.keys(envPathObject).find((key) => envPathObject[key].sharedPath === parameter.Name); const envName = envKey ? envPathObject[envKey].name : envPathObject[parameter.Name]?.name; process.env[envName] = parameter.Value; } } } return response; }; const response = await resolveSecrets(paths); const sharedPaths = (response?.InvalidParameters || []) .map((invalidParam) => envPathObject[invalidParam].sharedPath) .filter((sharedParam) => !!sharedParam); if (sharedPaths.length > 0) { await resolveSecrets(sharedPaths); }};await internalAmplifyFunctionResolveSsmParams();const SSM_PARAMETER_REFRESH_MS = 1000 * 60;setInterval(() => { void internalAmplifyFunctionResolveSsmParams();}, SSM_PARAMETER_REFRESH_MS);export {}; --inject:C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\@aws-amplify\backend-function\lib\lambda-shims\cjs_shim.js at checkExecSyncError (node:child_process:890:11) at Object.execFileSync (node:child_process:926:15) at Object. (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\esbuild\bin\esbuild:221:28) at Module._compile (node:internal/modules/cjs/loader:1356:14) at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) at Module.load (node:internal/modules/cjs/loader:1197:32) at Module._load (node:internal/modules/cjs/loader:1013:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) at node:internal/main/run_main_module:28:49 { status: 1, signal: null, output: [ null, null, null ], pid: 34788, stdout: null, stderr: null }

Node.js v18.19.1 C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:2 ),localBundling=options.local?.tryBundle(bundleDir,options),!localBundling){const assetStagingOptions={sourcePath:this.sourcePath,bundleDir,...options};switch(options.bundlingFileAccess){case bundling_1().BundlingFileAccess.VOLUME_COPY:new(asset_staging_1()).AssetBundlingVolumeCopy(assetStagingOptions).run();break;case bundling_1().BundlingFileAccess.BIND_MOUNT:default:new(asset_staging_1()).AssetBundlingBindMount(assetStagingOptions).run();break}}}catch(err){const bundleErrorDir=bundleDir+"-error";throw fs().existsSync(bundleErrorDir)&&fs().removeSync(bundleErrorDir),fs().renameSync(bundleDir,bundleErrorDir),new Error(Failed to bundle asset ${this.node.path}, bundle output is located at ${bundleErrorDir}: ${err})}if(fs_1().FileSystem.isEmpty(bundleDir)){const outputDir=localBundling?bundleDir:AssetStaging.BUNDLING_OUTPUT_DIR;throw new Error(Bundling did not produce any output. Check that content is written to ${outputDir}.)}}calculateHash(hashType,bundling,outputDir){if(hashType==assets_1().AssetHashType.CUSTOM||hashType==assets_1().AssetHashType.SOURCE&&bundling){const hash=crypto().createHash("sha256");return hash.update(this.customSourceFingerprint??fs_1().FileSystem.fingerprint(this.sourcePath,this.fingerprintOptions)),bundling&&hash.update(JSON.stringify(bundling,sanitizeHashValue)),hash.digest("hex")}switch(hashType){case assets_1().AssetHashType.SOURCE:return fs_1().FileSystem.fingerprint(this.sourcePath,this.fingerprintOptions);case assets_1().AssetHashType.BUNDLE:case assets_1().AssetHashType.OUTPUT:if(!outputDir)throw new Error(Cannot use `${hashType}` hash type when `bundling` is not specified.);return fs_1().FileSystem.fingerprint(outputDir,this.fingerprintOptions);default:throw new Error("Unknown asset hash type.")}}}exports.AssetStaging=AssetStaging,_a=JSII_RTTI_SYMBOL_1,AssetStaging[_a]={fqn:"aws-cdk-lib.AssetStaging",version:"2.134.0"},AssetStaging.BUNDLING_INPUT_DIR="/asset-input",AssetStaging.BUNDLING_OUTPUT_DIR="/asset-output",AssetStaging.assetCache=new(cache_1()).Cache;function renderAssetFilename(assetHash,extension=""){returnasset.${assetHash}${extension}}function determineHashType(assetHashType,customSourceFingerprint){const hashType=customSourceFingerprint?assetHashType??assets_1().AssetHashType.CUSTOM:assetHashType??assets_1().AssetHashType.SOURCE;if(customSourceFingerprint&&hashType!==assets_1().AssetHashType.CUSTOM)throw new Error(Cannot specify `${assetHashType}` for `assetHashType` when `assetHash` is specified. Use `CUSTOM` or leave `undefined`.);if(hashType===assets_1().AssetHashType.CUSTOM&&!customSourceFingerprint)throw new Error("assetHashmust be specified whenassetHashTypeis set toAssetHashType.CUSTOM.");return hashType}function calculateCacheKey(props){return crypto().createHash("sha256").update(JSON.stringify(sortObject(props),sanitizeHashValue)).digest("hex")}function sortObject(object){if(typeof object!="object"||object instanceof Array)return object;const ret={};for(const key of Object.keys(object).sort())ret[key]=sortObject(object[key]);return ret}function sanitizeHashValue(key,value){if(key==="PIP_INDEX_URL"||key==="PIP_EXTRA_INDEX_URL")try{let url=new URL(value);if(url.password)return url.password="",url.toString()}catch(e){throw e.name==="TypeError"?new Error(${key} must be a valid URL, got ${value}.):e}return value}function findSingleFile(directory,archiveOnly){if(!fs().existsSync(directory))throw new Error(Directory ${directory} does not exist.);if(!fs().statSync(directory).isDirectory())throw new Error(${directory} is not a directory.);const content=fs().readdirSync(directory);if(content.length===1){const file=path().join(directory,content[0]),extension=getExtension(content[0]).toLowerCase();if(fs().statSync(file).isFile()&&(!archiveOnly||ARCHIVE_EXTENSIONS.includes(extension)))return file}}function determineBundledAsset(bundleDir,outputType){const archiveFile=findSingleFile(bundleDir,outputType!==bundling_1().BundlingOutput.SINGLE_FILE);switch(outputType===bundling_1().BundlingOutput.AUTO_DISCOVER&&(outputType=archiveFile?bundling_1().BundlingOutput.ARCHIVED:bundling_1().BundlingOutput.NOT_ARCHIVED),outputType){case bundling_1().BundlingOutput.NOT_ARCHIVED:return{path:bundleDir,packaging:assets_1().FileAssetPackaging.ZIP_DIRECTORY};case bundling_1().BundlingOutput.ARCHIVED:case bundling_1().BundlingOutput.SINGLE_FILE:if(!archiveFile)throw new Error("Bundling output directory is expected to include only a single file whenoutputis set toARCHIVEDorSINGLE_FILE`");return{path:archiveFile,packaging:assets_1().FileAssetPackaging.FILE,extension:getExtension(archiveFile)}}}function getExtension(source){for(const ext of ARCHIVE_EXTENSIONS)if(source.toLowerCase().endsWith(ext))return ext;return path().extname(source)}

                                                                          ^

Error: Failed to bundle asset amplify-nextamplifygen2-GuyPavlov-sandbox-5763ff2c4a/function/presigned-url-lambda/Code/Stage, bundle output is located at C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal.amplify\artifacts\cdk.out\bundling-temp-e9230d152b0810080159375cfbc0a4ef95e64e8e4cd66a766f288da9cc5dba82-error: Error: cmd /c npx.cmd --no-install esbuild --bundle "C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\amplify\functions\presigned-url\handler.ts" --target=node18 --platform=node --format=esm --outfile="C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal.amplify\artifacts\cdk.out\bundling-temp-e9230d152b0810080159375cfbc0a4ef95e64e8e4cd66a766f288da9cc5dba82\index.mjs" --external:@aws-sdk/* --loader:.node=file --banner:js="/* This code loads environment values from SSM and places them in their corresponding environment variables. If there are no SSM environment values for this function, this is a noop. /import { SSM } from '@aws-sdk/client-ssm';/* Reads SSM environment context from a known Amplify environment variable, fetches values from SSM and places those values in the corresponding environment variables /export const internalAmplifyFunctionResolveSsmParams = async (client = new SSM()) => { const envPathObject = JSON.parse(process.env.AMPLIFY_SSM_ENV_CONFIG ?? '{}'); const paths = Object.keys(envPathObject); if (paths.length === 0) { return; } const resolveSecrets = async (paths) => { const response = await client.getParameters({ Names: paths, WithDecryption: true, }); if (response.Parameters && response.Parameters.length > 0) { for (const parameter of response.Parameters) { if (parameter.Name) {
const envKey = Object.keys(envPathObject).find((key) => envPathObject[key].sharedPath === parameter.Name); const envName = envKey ? envPathObject[envKey].name : envPathObject[parameter.Name]?.name; process.env[envName] = parameter.Value; } } } return response; }; const response = await resolveSecrets(paths); const sharedPaths = (response?.InvalidParameters || []) .map((invalidParam) => envPathObject[invalidParam].sharedPath) .filter((sharedParam) => !!sharedParam); if (sharedPaths.length > 0) { await resolveSecrets(sharedPaths); }};await internalAmplifyFunctionResolveSsmParams();const SSM_PARAMETER_REFRESH_MS = 1000 * 60;setInterval(() => { void internalAmplifyFunctionResolveSsmParams();}, SSM_PARAMETER_REFRESH_MS);export {};" --inject:C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\@aws-amplify\backend-function\lib\lambda-shims\cjs_shim.js run in directory C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal exited with status 1 at AssetStaging.bundle (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:2:619) at AssetStaging.stageByBundling (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:5297) at stageThisAsset (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:2728)
at Cache.obtain (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\private\cache.js:1:242)
at new AssetStaging (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:3125)
at new Asset (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\aws-s3-assets\lib\asset.js:1:1080) at AssetCode.bind (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\aws-lambda\lib\code.js:1:4881)
at new Function (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\aws-lambda\lib\function.js:1:9422)
at new NodejsFunction (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\aws-cdk-lib\aws-lambda-nodejs\lib\function.js:1:1669) at AmplifyFunction (C:\Users\Guy Pavlov\UpWork\ad-platform\ad-portal\node_modules\@aws-amplify\backend-function\src\factory.ts:292:28)

Node.js v18.19.1 Subprocess exited with error 1

[Sandbox] Watching for file changes...