Search code examples
javascriptreactjsreact-nativeaws-lambdaaws-amplify

How to resolve error: Could not initialize platform for 'dev': Access Denied in AWS Amplify


I cloned a repo to follow through on a tutorial. The Github repo has amplify folder already, meaning the original developer had already initialized amplify in the project. How do I successfully run amplify init? Because whenever I run the code I will get this error below:

$ 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: dev Using default provider awscloudformation ✖ Initializing your environment: dev ✖ There was an error initializing your environment. 🛑 Could not initialize platform for 'dev': Access Denied

Thanks for your help.


Solution

  • Based on the error you are getting I have to ask. Are you sure you are in the root directory of the cloned repo. Sometimes it's easy to accidently navigate to the directory where your frontend is .ie React-Native, Next js etc.

    I believe the command you're looking for is amplify pull. If there is already an amplify directory in your root directory, running amplify init could cause you to run into some issues.

    In your root directory.

    amplify pull
    

    Also, make sure you have all the proper dependencies installed for the resources in Amplify. Check the package.json for dependencies that may need to be installed. Below is an example.

    An example for a lambda function with dependencies.

    cd amplify/backend/function/<function_name>/src
    

    run:

    npm install
    

    Hope this helps.