We will be using React-Native and Expo to develop our mobile app. The React-Native application is pre-created for you (using create-react-native-app
method). We will be using the Expo client on your mobile device to preview the app as we build it. Expo has two main components - the Expo development server and the mobile client. We will run a React Native and expo development server inside a docker container on AWS Cloud9.
Configure Cloud9
Configure React Native Docker Environment
Configure Expo
-
Click the link here to go to Cloud9 console. Sign in with your credentials if necessary. You need to be in Singapore region for this lab.
-
Give any appropriate name and description to your environment. Click on Next.
-
Choose M4.large instance type and click on Next.
-
Click on Create Environment.
-
While it is being built, you may move on to the next section.
-
After a few minutes, when your environment is up, you should see following screen.
We are going to create a new IAM user with the required access to the AWS resources. So, we do not need AWS Cloud9 to manage temporary credentials for us.
-
At Preference, go to AWS Setting
Your Cloud9 instance is allocated 8 GB storage by default. We will increase this because we will be installing dependencies.
-
Go to your running instances by clicking here
-
Find the instance you have just created by launching a Cloud9 environment. The name will be
aws-cloud9-<your environment name>-<random string>
-
Select the instance. Scroll down at the bottom part. Find the Block devices.
-
Click on Yes and wait for the change to finish. It will take a couple of minutes.
-
Go back and select your instance. Reboot that instance to make sure the EBS changes take effect.
AWS Cloud9 restricts inbound access to the IP addresses it uses to connect to the instance. In addition, we will need to allow traffic on 19000
and 19001
, both of which are used by Expo. The Expo server runs on port 19000
while the npm package manager is exposed on 19001
. Refer to the Expo docs to learn more.
-
Go back to the tab where you have the EC2 instances.
AWS Cloud9 environment comes pre-installed with Docker.
-
Let's create a working directory. We have chosen the name as rn. Type
mkdir rn
to create the directory. Press Enter key. -
Create a
Dockerfile
which is the definition of the docker container that will host our Expo development environment. Typetouch Dockerfile
. And press Enter key. You will find a Dockerfile created inside thern
folder. -
Copy the following commands and paste inside the file. Take a few minutes to review this file. We are also installing the AWS mobile CLI.
FROM node:11.1.0
RUN mkdir -p /code
WORKDIR /code
RUN apt-get update && apt-get install -y python-dev screen
RUN cd /tmp/ && git clone https://github.com/facebook/watchman.git && \
cd watchman && git checkout v4.9.0 && ./autogen.sh && \
./configure && make -j4 && make install && cd / && rm -rf /tmp/watchman
# RUN npm set progress=false && \
RUN npm install -g create-react-native-app expo-cli @aws-amplify/cli
# CHANGE the UID accordingly, follow the step at the note section.
RUN useradd -m -u 501 -s /bin/bash ec2-user
Note: find out what is your cloud UID by doing echo $UID
. By default (at this time of the workshop), the UID is 501.
-
Save it by pressing
Command + S
keys for Mac. OrControl + S
keys for Windows. You can see All Changes Saved sign at the top of the Cloud9 Window. -
Go back to the lower window. Key in
docker build -t reactnative-expo .
and press Enter key. Notice this command ends with a dot. -
This will take a few minutes. You might see some
npm warnings
in red around optional dependencies. You can ignore them. -
You can verify your image was successfully built by typing
docker images
. You should see areactnative-expo
image. -
Start the React Native Docker using this image with the command below. This step allows us to use AWS Cloud9 to be the IDE for our React Native project under the directory
~/environment/rn
while having a Docker container execute the React Native and Expo development server. The 2 TCP ports (19000, 19001) allows our mobile device to communicate with the React Native/Expo container.
cd ~/environment/rn
docker run -it --rm -p 19000:19000 -p 19001:19001 \
-v "$PWD:/code" --user $UID \
-v /home/ec2-user/.aws:/home/ec2-user/.aws \
-v /home/ec2-user/.awsmobilejs:/home/ec2-user/.awsmobilejs \
-e REACT_NATIVE_PACKAGER_HOSTNAME=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4` \
reactnative-expo:latest bash
Now that you are in the container, run amplify --version
to double check that the amplify CLI has been properly installed in the docker container.
Follow the installation instructions for your mobile device on the official Expo website
Create an Expo account via the offical Expo website
Now you have successfully setup Expo and your AWS Cloud9 in your AWS Console. You can now proceed to Lab 2 to work on setting up the AWS Amplify CLI.