Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run an existing aws amplify project

I have been asked to work on an existing aws amplify reactJs project. Normally I would simply clone the project repo from either github or bitbucket, but this project is am amplify project and requires a whole set of configuration. I have several aws profiles set-up on the cli, and have access to the aws cludservices for this project, but cannot run the app locally because my aws-exports.js file does not have the required auhtentication configurations in it.

According to the amplify cli docs for an existing project, I should just be able to run amplify init --app https://bitbucket.org/brooklynva/brooklyn-ocr-poc.git. However this tried, and thankfully failed, to update the cloudformation stack on aws. It updated the aws-exports.js file but only with this:

// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "us-east-2"
};


export default awsmobile;

So I then found that running amplify pull --frontend with some other parameters which I put into a bash file would be the equivalent of running git pull. After running that command, still nothing was updated in the config file.

#!/bin/bash
set -e
IFS='|'

REACTCONFIG="{\
\"SourceDir\":\"src\",\
\"DistributionDir\":\"build\",\
\"BuildCommand\":\"npm run-script build\",\
\"StartCommand\":\"npm run-script start\"\
}"
FRONTEND="{\
\"frontend\":\"javascript\",\
\"framework\":\"react\",\
\"config\":$REACTCONFIG\
}"

amplify pull \
--frontend $FRONTEND \
--yes

So my question remains, how do I start an already existing aws amplify app from an existing project and generate the configuration file necessary to run the app locally without having the person who created the app, share that config file with me?

like image 388
hyprstack Avatar asked Apr 08 '20 15:04

hyprstack


2 Answers

For me what worked was using the amplify init command passing appId instead of the repo url. E.g. amplify init --appId YOUR_APP_ID

like image 180
Francisco Facal Avatar answered Nov 14 '22 04:11

Francisco Facal


You need to create or use an existing Amplify environment

Check the environments you have available

amplify env list

Similar to git, it will show the list of environments (think about this as branches on git)

Check out one of the existing environment or create a new one for you, Amplify allows you to create an environment, for example, for a specific user, i.e: dev-myuser

amplify env checkout <exising-environment>

or

amplify env add

The add command is interactive and will ask you a few questions to set up your environment

After that, you should have your aws-exports.js set

Then you push your changes

amplify push

More details about Amplify environments: https://read.acloud.guru/multiple-serverless-environments-with-aws-amplify-344759e1be08

From the official documentation: https://aws-amplify.github.io/docs/cli-toolchain/quickstart#environments-and-teams

like image 37
dfranca Avatar answered Nov 14 '22 04:11

dfranca