I'm trying to get the CI/CD release process working so that when I commit to the release branch, it runs the amplify push process.
I AM able to amplify push
locally without any issues (after switching branches and checking out the correct amplify environment).
This application has two environments: 'staging' and 'live'. I have two separate AWS accounts for these environments. I created and tested the project initially in staging. When testing was done, I created a new AWS account, created a new Amplify project, and connected it to the 'live' branch in my repo.
When I push commits to the 'live' branch, it starts a build, and gets through provisioning and the pre-build stages. Then I get this:
# Starting phase: build
2022-04-06T17:57:48.997Z [INFO]: Amplify AppID found: xxxxxxxxxxxx. Amplify App name is: Project Production
2022-04-06T17:57:49.080Z [INFO]: Backend environment live found in Amplify Console app: Project Production
2022-04-06T17:57:56.229Z [WARNING]: - Fetching updates to backend environment: live from the cloud.
2022-04-06T17:58:02.363Z [WARNING]: - Building resource api/myapi
2022-04-06T17:58:13.032Z [INFO]: GraphQL schema compiled successfully.
Edit your schema at /codebuild/output/src656745275/src/project-name/amplify/backend/api/myapi/schema.graphql or place .graphql files in a directory at /codebuild/output/src656745275/src/project-name/amplify/backend/api/myapi/schema
2022-04-06T17:58:13.033Z [WARNING]: - Building resource api/restapi
2022-04-06T17:58:17.485Z [WARNING]: - Building resource custom/MagicLinkEmailTemplate
2022-04-06T17:58:17.486Z [WARNING]: - Building custom resources
2022-04-06T17:58:32.284Z [WARNING]: - Building resource custom/MyCustomResource
- Building custom resources
2022-04-06T17:58:48.882Z [WARNING]: - Building resource custom/MyStateMachine
2022-04-06T17:58:48.883Z [WARNING]: - Building custom resources
2022-04-06T17:59:04.647Z [WARNING]: - Building resource custom/HostedZone
- Building custom resources
2022-04-06T17:59:23.823Z [WARNING]: ✔ Successfully pulled backend environment live from the cloud.
2022-04-06T17:59:23.934Z [INFO]:
2022-04-06T17:59:25.368Z [INFO]: Note: It is recommended to run this command from the root of your app directory
2022-04-06T17:59:27.068Z [WARNING]: - Initializing your environment: live
2022-04-06T17:59:33.150Z [WARNING]: - Building resource api/myapi
2022-04-06T17:59:39.389Z [INFO]: GraphQL schema compiled successfully.
Edit your schema at /codebuild/output/src656745275/src/project-name/amplify/backend/api/myapi/schema.graphql or place .graphql files in a directory at /codebuild/output/src656745275/src/project-name/amplify/backend/api/myapi/schema
2022-04-06T17:59:39.390Z [WARNING]: - Building resource api/restapi
2022-04-06T17:59:43.825Z [WARNING]: - Building resource custom/MagicLinkEmailTemplate
2022-04-06T17:59:43.828Z [WARNING]: - Building custom resources
2022-04-06T17:59:50.278Z [WARNING]: - Building resource custom/MyCustomResource
- Building custom resources
2022-04-06T17:59:58.898Z [WARNING]: - Building resource custom/MyStateMachine
- Building custom resources
2022-04-06T18:00:06.435Z [WARNING]: - Building resource custom/HostedZone
- Building custom resources
2022-04-06T18:00:16.067Z [WARNING]: ✔ Initialized provider successfully.
2022-04-06T18:00:17.268Z [INFO]:
2022-04-06T18:00:17.274Z [INFO]: Suggested configuration for new layer versions:
2022-04-06T18:00:17.282Z [INFO]: myappLayerGraphQL
- Access permissions: Maintain existing permissions
- Description: Updated layer version 2022-04-06T18:00:17.273Z
myappLayerAxios
- Access permissions: Maintain existing permissions
- Description: Updated layer version 2022-04-06T18:00:17.273Z
myappLayerLodash
- Access permissions: Maintain existing permissions
- Description: Updated layer version 2022-04-06T18:00:17.273Z
myappLayerStripe
- Access permissions: Maintain existing permissions
- Description: Updated layer version 2022-04-06T18:00:17.273Z
2022-04-06T18:00:17.282Z [INFO]:
2022-04-06T18:00:31.140Z [WARNING]: ✖ An error occurred when pushing the resources to the cloud
2022-04-06T18:00:31.162Z [WARNING]: ✖ There was an error initializing your environment.
2022-04-06T18:00:31.170Z [INFO]: Error: Packaging lambda function failed with the error
Command failed with exit code 1: npm install --production
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
npm WARN tar ENOENT: no such file or directory, open '/codebuild/output/src656745275/src/project-name/amplify/backend/function/myappLayerGraphQL/lib/nodejs/node_modules/.staging/graphql-03f7efb5/language/directiveLocation.mjs'
npm WARN tar ENOENT: no such file or directory, open '/codebuild/output/src656745275/src/project-name/amplify/backend/function/myappLayerGraphQL/lib/nodejs/node_modules/.staging/graphql-03f7efb5/type/directives.mjs'
npm WARN tar ENOENT: no such file or directory, open '/codebuild/output/src656745275/src/project-name/amplify/backend/function/myappLayerGraphQL/lib/nodejs/node_modules/.staging/graphql-03f7efb5/execution/execute.mjs'
......
Those errors go on for about 400 more lines...
I don't know what that .staging directory is or where it came from -- it's not in my actual layer, I don't see references to 'staging' in any files in that entire layer directory.
Any help, please?!
Something changed in Amplify and I started getting a different error message which led me to the solution.
It turns out that I hadn't properly authorized the build process to install the private NPM package I had up on GitHub Package Manager. I dropped the .npmrc
file that I had in my local user directory into the directory that contained the package.json
for the function that was failing and it started working.
Simple solution made more difficult by bad error logging...