Error initializing environment after running "amplify init." - reactjs

Working on a web app using react.js that I picked up from another developer. Currently, trying to use AWS Amplify and I will eventually use AWS Cognito for authentication purposes.
I am using the following tutorial: https://hackernoon.com/react-authentication-in-depth-4deebda9aa45
I've already executed the following commands:
$ npm i -g #aws-amplify/cli
$ amplify configure
I've set up my CLI with the amplify config command, to include setting up the environment, access key ID and Secret Access key.
Error comes after running
$ amplify init
I've already seen a stack overflow post that states that this is a known error for the CLI, and that a fix has been implemented in the latest version of the CLI. I've tried updating amplify and re-installing. This is my second attempt to reinstall.
Here is a copy of the error in terminal.
MacBook-Air% amplify init
Note: It is recommended to run this command from the root of your app directory
? Do you want to use an existing environment? Yes
? Choose the environment you would like to use: discrete
Using default provider awscloudformation
✖ There was an error initializing your environment.
init failed
{ AccessDenied: Access Denied
at Request.extractError (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/services/s3.js:585:35)
at Request.callListeners (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
message: 'Access Denied',
code: 'AccessDenied',
region: null,
time: 2019-05-01T18:09:17.901Z,
requestId: '7814262360A7DF07',
extendedRequestId:
'Y1woT4qs3VOtSCQG7sWNu7zexB2O+ZNP3oiBugTdfkHbK4Um5vzOS05P5qsZRcRFUPVTAbey8Q0=',
cfId: undefined,
statusCode: 403,
retryable: false,
retryDelay: 155.200421877319 }
Expect environment to properly initialize and amplify to be properly configured.

In my case, I cloned a repo from codecommit and doing amplify init and facing the same problem. To solve this, I rename aws-export.js to aws-export.mjs and again run amplify init and it initialize the project without any error.

You can check those issues reported at github project.
We had a similar issue using '#aws-amplify/cli' is version: '2.0.0', at aws Amplify Console.
Our envs develop, PR, etc. were building fine but master did not.
So, we change the version from 2.0.0 to 4.0.0 and build start working again.
Check
Console broken again (probably related to aws-amplify/cli 2.0.0)
AccessDenied error when deploying backend

It looks like the git repo has already teamproviderinfo.json present or some environment setting checking conflicting with your current setting. So when you try to init the project with environment name 'dev' or the one with the copied repo from git, it is trying to reuse the existing resources.
Solution: Try using a different name for the environment instead of dev and see if that works.
In my case it solved such issue.

Related

deploying MERN stack, using github pages and heroku

I am following this guide to deploy MERN stack app, using heroku and github pages -https://github.com/juliojgarciaperez/deploy-mern
Q1. Do I need to create 2 different repositories, 1 for backend and 1 for frontend to connect to heroku? (t.ex backend repository to the heroku pipeline) I originally developed both backend and frontend under same repository.
Q2. I managed to get the step:3 in guide, and created the new base set up for react app, following the guide mentioned - https://elements.heroku.com/buildpacks/mars/create-react-app-buildpack
after generating the react app using this buildpack command, I replace the src and public with what I have written before, also install the dependencies.
but when I run the git push heroku master command in terminal,
I get errors saying
error: failed to push some refs to 'https://git.heroku.com/apprepositorynamehere.git'
And when I read the process, it says
engines.node (package.json): unspecified
Cannot find module: 'react-router-dom'. Make sure this package is installed.
You can install this package by running: yarn add react-router-dom.
error Command failed with exit code 1.
To solve each problem, I add the node with specified version in package.json
"engines": {
"node": "13.7.0"
},
and also ran the yarn add command to install the react-router-dom
But none of the issues goes away when i re-run the git push heroku master.
I originally create the react app and developed in npm setting not yarn.
I wonder if this is causing the issue where copy pasting my previous src?
I wanted to use the github pages bcs it is easy to deal with but If anyone has any other suggestion, to deploy MERN stack app, I am opened to it!
To anybody who is looking for an answer to my previous question.
I did not use the github page to deploy my MERN stack app,
but used this tutorial 'https://www.youtube.com/watch?v=qdoiwouykAg'
A1. You do not need 2 different repository, but need to configure your package.json in both frontend and backend.
A2. I still see this in terminal, but it does resolve.
Resolving node version 12.x...

Error pushing ReactJS (CRA template) code to GitHub enterprise

After cloning the empty repository I created in my Github Enterprise account, I created a CRA (create-react-app) ReactJS application. I created, committed & pushed a README.md file before generating the CRA scaffolding and it got pushed successfully. But, after CRA app got generated, I'm not able to push the code to the GitHub Enterprise server.
Git Bash throws the following error:
remote: fatal: early EOF
Whereas GitHub Desktop throws the following:
error: RPC failed; curl 56 Failure when receiving data from the peer
I have been using GitHub enterprise for NodeJS web app dev for years now and have never faced any issue of such sort but I have not been able to push the CRA based React app scaffolding code.
I have tried referring to the following StackOverflow posts:
Your configuration specifies to merge with the <branch name> from the remote, but no such ref was fetched.?
Git push error '[remote rejected] master -> master (branch is currently checked out)'
Cannot push to GitHub - keeps saying need merge
but those didn't work. Apparently, this use case is unique as the error only gets thrown (from all my experience working with this GitHub enterprise account) when I'm pushing CRA code and no other.
Attachments (Git Bash & GitHub Desktop errors):
This has been answered here: https://stackoverflow.com/a/36843260/1673761
Look here: https://flyingtomoon.com/2011/04/12/git-push-is-failed-due-to-rpc-failure-result56/
The problem is most likely because your git buffer is too low.
You will need to increase Git’s HTTP buffer by setting the git config var “http.postBuffer” to 524288000.
git config http.postBuffer 524288000

Google cloud: invalid build: failed to check access to key

Trying to create cloudbuild config for App Engine on Google cloud.
There are some encrypted environment variables that app needs. I did everything as this documentation says. When new Git commit has been pushed I'm always getting this error in cloudbuild log:
invalid build: failed to check access to "projects/$PROJECT_ID/locations/global/keyRings/my-key-ring/cryptoKeys/my-key"
Also, there is one more question. If I execute gcloud app deploy command from my laptop app is being deployed and then fails to run because of absent environment variables. Is that correct that I need to define these variables along with command like
> MY_VAR1=a MY_VAR2=b gcloud app deploy
?
And if that's correct why it's not working?
I think the error is that the $PROJECT_ID variable is not supported in the kmsKeyName field. I had the same error and replacing $PROJECT_ID with my literal project-name was the fix.
See https://stackoverflow.com/a/56984975/771768 for a related problem.

Unable to resolve "./aws-exports" from "App.js"

I have been building an app with awsamplify for quite some time now. Today I descided to run some test and when I did
npm run start-web
Everythin worked fine. Now I went on to run mobile test with the use of Expo and ran
npm run ios & npm run android
which both returned the following errors.
Unable to resolve "./aws-exports" from "App.js"
Building JavaScript bundle: error
my problem is similar to the one below just its amplify and not awsmobile
https://github.com/aws-amplify/amplify-js/issues/669
Deos anyone know what I can do to resolve this?
Thanks alot!
I jsut removed some unused imports and the error changed to this
Unable to resolve "#aws-amplify/ui/dist/style.css" from "node_modules\aws-amplify-react\dist\Amplify-UI\Amplify-UI-Components-React.js"
Barely mentioned in the AWS docs:
For setting up a local dev folder, from an existing amplify repo, use an amplify env pull,
It will "pull" the ./aws-exports.js from the server, the latest one that was pushed there,
similar to git push and git pull but for the amplify env
It's true that an amplify push will create the ./aws-exports.js file,
but it will also "push" it to the server, overwriting whatever is there.
amplify status is also a handy command, similar to git status
I ran amplify env pull
and then found it in the ./src/aws-exports.js
not sure if the pull did it, or if it was always there but this is for an existing expo project
Confing your projects, using terminal go to the main folder and amplify init to config your project
amplify init
Do you to use an existing environment? (Y/n) Y
Choose the environment you would like to use: dev
Choose your default editor: Visual Studio Code
Choose the type of app you're building: javascript
What javascript framework you're using: ionic
Source Directory Path: src
Distribution Directory Path: www
Build Command: npm run-script build
Do you want to use an AWS profile? Y
Please choose the profile you want to use: select your personal IAM profile

Using gcloud on Travis CI

I have gcloud installed and working and a service account gets also activated. I run the following and get a success(?):
$ gcloud auth activate-service-account "${GAE_CLIENT_ACCOUNT}" --key-file "${GAE_CLIENT_KEY_JSON_FILE}"
Activated service account credentials for: [xxxxx#developer.gserviceaccount.com]
Then I run this:
$ gcloud preview app deploy app.yaml --project "${GAE_PROJECT_ID}" --quiet --version "${GAE_PROJECT_VERSION}"
You are about to deploy the following modules:
- ricochet-robots/default/dev From: [/home/travis/build/ricochetrobots/ricochetrobots-landing/app.yaml]
Updating module [default]...Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=xxxxxxxx.apps.googleusercontent.com&access_type=offline
Updating module [default].../
As you can see, it prompts me to follow the link and do an oauth. Because I'm on a ci server, it's not possible to follow the link.
How kan I suppress that? Or is there a totally diffrent way of deploying the app automatically.
This is a known issue in version 0.9.61.
For now, you can work around by pinning to a previous version:
gcloud config set component_manager/fixed_sdk_version 0.9.60
gcloud components update
Since you're running in a CI server, you can also set the following environment variable, if you run gcloud components update in your script. This may be an easier fix, depending on your CI server.
CLOUDSDK_COMPONENT_MANAGER_SNAPSHOT_URL=https://dl.google.com/dl/cloudsdk/release/components-v0.9.60.json
Running gcloud preview app deploy --set-default using a service account has the same issue in versions 0.9.57 through 0.9.62. If you'd like to use this command, you can pin to 0.9.56.
We're targeting a fix for version 0.9.63 or shortly thereafter. Follow the issue on the gcloud bug tracker for more updates.
EDIT: This issue was fixed in version 0.9.63.

Resources