Describe the bug
The following page states that aws-exports.js will be created by Amplify CLI when running amplify push command:
https://aws-amplify.github.io/docs/js/start?platform=react-native
How it Works: Rather than configuring each service through a constructor or constants file, Amplify supports configuration through a centralized file called aws-exports.js which defines all the regions and service endpoints to communicate. Whenever you run amplify push, this file is automatically created allowing you to focus on your application code. The Amplify CLI will place this file in the appropriate source directory configured with amplify init.
To Reproduce
Steps to reproduce the behavior:
Without this project, the application will not execute since all Amplify modules depend on this configuration being loaded at runtime.
Expected behavior
amplify push will create or update aws-exports.js when the command completes successfully
Desktop (please complete the following information):
npm install -g @aws-amplify/cli
"aws-amplify": "^1.1.36",
"aws-amplify-react-native": "^2.1.16",
Smartphone (please complete the following information):
Sample code
The code from AWS Amplify readme:
import Amplify from 'aws-amplify';
import aws_exports from './aws-exports';
Amplify.configure(aws_exports);
@01binary Which version of the CLI are you using? During ampify init
- what's the project type did you select - between javascript/android/iOS for the Choose the type of app that you're building
question in the prompt?
Also could you please share your <project-root>/amplify/.config/project-config.json
file?
I installed the latest version of the CLI with the following propmpts and it created an aws_exports.js
file inside the src/ directory of my project.
f45c89966b0d:testexports kaustavg$ amplify init
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project testexports
? Enter a name for the environment dev
? Choose your default editor: Sublime Text
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using none
? Source Directory Path: src
? Distribution Directory Path: dist
? Build Command: npm run-script build
? Start Command: npm run-script start
Using default provider awscloudformation
For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html
? Do you want to use an AWS profile? Yes
? Please choose the profile you want to use default
â ´ Initializing project in the cloud...
CREATE_IN_PROGRESS DeploymentBucket AWS::S3::Bucket Tue Aug 13 2019 15:44:24 GMT-0700 (Pacific Daylight Time) Resource creation Initiated
CREATE_IN_PROGRESS UnauthRole AWS::IAM::Role Tue Aug 13 2019 15:44:24 GMT-0700 (Pacific Daylight Time) Resource creation Initiated
CREATE_IN_PROGRESS AuthRole AWS::IAM::Role Tue Aug 13 2019 15:44:24 GMT-0700 (Pacific Daylight Time) Resource creation Initiated
CREATE_IN_PROGRESS UnauthRole AWS::IAM::Role Tue Aug 13 2019 15:44:23 GMT-0700 (Pacific Daylight Time)
CREATE_IN_PROGRESS DeploymentBucket AWS::S3::Bucket Tue Aug 13 2019 15:44:23 GMT-0700 (Pacific Daylight Time)
CREATE_IN_PROGRESS AuthRole AWS::IAM::Role Tue Aug 13 2019 15:44:23 GMT-0700 (Pacific Daylight Time)
CREATE_IN_PROGRESS testexports-dev-20190813154419 AWS::CloudFormation::Stack Tue Aug 13 2019 15:44:20 GMT-0700 (Pacific Daylight Time) User Initiated
â § Initializing project in the cloud...
CREATE_COMPLETE UnauthRole AWS::IAM::Role Tue Aug 13 2019 15:44:38 GMT-0700 (Pacific Daylight Time)
CREATE_COMPLETE AuthRole AWS::IAM::Role Tue Aug 13 2019 15:44:38 GMT-0700 (Pacific Daylight Time)
â § Initializing project in the cloud...
CREATE_COMPLETE DeploymentBucket AWS::S3::Bucket Tue Aug 13 2019 15:44:45 GMT-0700 (Pacific Daylight Time)
â ¦ Initializing project in the cloud...
CREATE_COMPLETE testexports-dev-20190813154419 AWS::CloudFormation::Stack Tue Aug 13 2019 15:44:47 GMT-0700 (Pacific Daylight Time)
✔ Successfully created initial AWS cloud resources for deployments.
✔ Initialized provider successfully.
Initialized your environment successfully.
Your project has been successfully initialized and connected to the cloud!
Some next steps:
"amplify status" will show you what you've added already and if it's locally configured or deployed
"amplify <category> add" will allow you to add features like user login or a backend API
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud
Pro tip:
Try "amplify add api" to create a backend API and then "amplify publish" to deploy everything
f45c89966b0d:testexports kaustavg$ ls src/
aws-exports.js
f45c89966b0d:testexports kaustavg$ cat src/aws-exports.js
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = {
"aws_project_region": "us-east-1"
};
export default awsmobile;
f45c89966b0d:testexports kaustavg$
@01binary Please comment on this thread if you're still stuck on this issue.
Sorry to create a dead-on-arrival issue, but Amplify is impossible to get working for mobile development and I am giving up on it in that context.
I had the same issue, and I think I know what happened here. I am also trying to make a react-native app...for android. TLDR; When building a react-native app, you need to tell Amplify that you're making a "javascript" app, not an "android" app.
If you say that you're building an "android" project when it asks "Choose the type of app that you're building", the next question ("Where is your Res directory?") has "app/src/main/res" as the default value. This builds a file called "awsconfiguration.json" in "app/src/main/res", which is NOT used by React-Native.
Instead, when it asks what type of app your are building, I needed to select "javascript". This then asks you which framework you are using, which will allow you to select "react-native" as one of the options. When amplify then asks for the source directory path (DIFFERENT QUESTION!), it defaults to "/", which is where we'd expect the program to build awsconfig.js.
same issue, Amplify doesn't seem very reliable
My issue was when I do the "amplify init/push" I was in the directory above my app, so the src/aws-export.js is created outside my app.
Hi! Long time reader, first time commenter. This might be an obvious first check issue but I thought AWS was not generating an AWS-exports.js file as it wasn't coming up in my code editor (using ATOM), but it turns out it was definitely created in my app directory but because the aws-exports file is listed in the .gitIgnore file, it wasn't coming up in the code editor's project menu. I don't know if that helps...
Most helpful comment
I had the same issue, and I think I know what happened here. I am also trying to make a react-native app...for android. TLDR; When building a react-native app, you need to tell Amplify that you're making a "javascript" app, not an "android" app.
If you say that you're building an "android" project when it asks "Choose the type of app that you're building", the next question ("Where is your Res directory?") has "app/src/main/res" as the default value. This builds a file called "awsconfiguration.json" in "app/src/main/res", which is NOT used by React-Native.
Instead, when it asks what type of app your are building, I needed to select "javascript". This then asks you which framework you are using, which will allow you to select "react-native" as one of the options. When amplify then asks for the source directory path (DIFFERENT QUESTION!), it defaults to "/", which is where we'd expect the program to build awsconfig.js.