For some reason, one of my functions refuses to build in branch builds. It works in sandbox mode, including completely fresh sandbox builds.
The error reported appears to have something to do with injecting the SSM secrets helper into this function. Of note, I am not using any secrets with this function. I've tried removing the function, then readding it to the project, and I still get the same error. Has anyone seen this, or do you have any ideas for what might be causing the bundle injection to fail?
Thanks!
233 2024-07-24T15:41:59.512Z [INFO]: NodeJSFunctionConstructInitializationError: Failed to instantiate nodejs function construct
234 Resolution: See the underlying error message for more details.
235 Cause: Failed to bundle asset amplify-[appid]-develop-branch-fa6d7c9088/function/[function name]/Code/Stage, bundle output is located at /codebuild/output/src2565109353/src/[app name]/.amplify/artifacts/cdk.out/bundling-temp-34810b71819b8ed1141ca70264cce619498c6f7893cb552751a08df7d54d1329-error: Error: bash -c npx --no-install esbuild --bundle "/codebuild/output/src2565109353/src/[app name]/amplify/functions/[function name]/handler.ts" --target=node20 --platform=node --format=esm --outfile="/codebuild/output/src2565109353/src/[app name]/.amplify/artifacts/cdk.out/bundling-temp-34810b71819b8ed1141ca70264cce619498c6f7893cb552751a08df7d54d1329/index.mjs" --minify --sourcemap --loader:.node=file --banner:js="/** * 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) => { const envPathObject = JSON.parse(process.env.AMPLIFY_SSM_ENV_CONFIG ?? '{}'); const paths = Object.keys(envPathObject); if (paths.length === 0) { return; } let actualSsmClient; if (client) { actualSsmClient = client; } else { const ssmSdk = await import('@aws-sdk/client-ssm'); actualSsmClient = new ssmSdk.SSM(); } const resolveSecrets = async (paths) => { const response = await actualSsmClient.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:"/codebuild/output/src2565109353/src/[app name]/node_modules/@aws-amplify/backend-function/lib/lambda-shims/cjs_shim.js" run in directory /codebuild/output/src2565109353/src/[app name] exited with status 1