Deploy Reactjs to AWS S3

In Tech
353 followers
4 Video Views·Dec 9, 2022
What's up folks, welcome back to another video on this channel, we help you become a full stack
developer. If you haven't subscribed yet, definitely consider do so. Well, this is an
entire series of where we're going to walk you guys through how we can deploy application like
Angular Vue JS and React JS application using Amazon s3. In this particular video, we're going
to deploy a react application to s3. In order to start, you definitely need at least to have an
AWS account. If you don't have one yet, definitely make sure that you have an AWS account. Well,
without any further ado, let's get our hands dirty. First thing first, navigate to wherever
you have a console log that aws.com. Once you're here, make sure that you search for s3 and click
on s3, it will take you this page, I'm going to go here and create what they call a bucket. And
think about a bucket of where you're going to store all your files. And this bucket name has
to be unique, I'm going to call my bucket name YouTube demo s3 and select the region where you
want it to be. Now make sure that you select the region that is closer to where your consumer is
going to be. And the reason being is going to make your application loads faster to where your end
consumer is, I'm going to select a region. Now you can leave the default one, that is okay. But I
would recommend for you guys to select the one that is closer to your end consumer so that the
application can load faster for them. So I'm going to leave the default one. And once that's done,
click Create. And believe it or not, we now have a bucket created into s3. Second thing we're going
to do is try to make this bucket public right now, this bucket is not public, which means nobody
ordered the new can access this bucket. So in order for us to do this, I'm going to go here and
click on the button and click wherever it said permission. And I'm going to go all the way it
said edit. And I'm going to make sure that I won't check this box. And once that's done, I'm going to
save that one. And I'm going to type the word confirm and click Confirm. And now this bucket
is public. Again, all I do is go to permission tab, go into public access and uncheck this public
field. Once that's done, the next step is we're going to attach what they call a bucket policy
into this bucket. So I'm going to click wherever it said bucket policy. Now a bucket policy,
it's something that gives the user the ability for them to read files inside your bucket,
create delete files inside of it as well. How can we do that? Well, if you head over this URL,
this URL will contain the policy that we are currently using, I'm going to go ahead here and
copy this policy, you're going to bring it over here and paste it. Now all we need to do inside
this policy is wherever we have the bucket name, we're going to replace it with the name of our
bucket. In this case, it is YouTube demo s3. So we're going to right click and copy this and we
place this one with the name of my bucket. And ladies and gentlemen, this bucket policy is
attached to this bucket. And all we need to do now is click on Save button and we're good to go.
Now to verify this work, we need to go back to Amazon s3. And we need to make sure that we are
seeing the label public to our bucket. If you do not see this, then just be mindful that your bucket
is not fully public. Once this done, make sure that you click on your public now. And what we're
going to do is we're going to try to bring our react application into that bucket. So how can
we do that? First thing first, let's go to wherever we have our react application. In this case,
this is my react application. And this is exactly what it looks like right now. And my goal is I
want to take this app that is currently running on the localhost 3000 into Amazon s3. So how can we
do that? First thing first, I need to go over the react application, I'm going to run what they call
NPM run bill, what is going to do for me is going to create a bill folder inside right here, there
you go, there's my bill folder is going to create a bill folder with everything that I needed in
order to deploy to Amazon s3. Now, if this command doesn't work for you guys, I'm definitely using
the create react app that give me the script in order for them to generate a static file for me.
So again, all we do is run this command here and go ahead and create this bill folder for me. Okay,
so the next step is we need to go wherever we have our react application, I'm going to click
on it, I'm going to go inside the bill folder, again, make sure that you are inside the bill
folder. And once I am inside the bill folder, I'm going to select everything and drag them over
inside my bucket like this. And boom, and all I need to do now is click wherever it said upload.
And ladies and gentlemen, everything that was inside a bill folder is now inside my s3 bucket
right here. Alright, the last step in order to get this live to the end consumer for everybody
to be able to see this live, I need to go to wherever we have property right here. And I'm
going to click where it says static website hosting. And I'm going to click on the first
one where it said use this bucket to host a website, I'm going to click on that, make sure
you specify index HTML, I'm going to copy the same thing and paste it as well in the error document.
And all I need to do now is click on Save. And now if I go back to the static website and click
on this URL right here, and ladies and gentlemen, our website, it is loading is fully deployed into
Amazon s3, I can share this entire URL with anybody they want. And they can be able to see
my website live and access and play one with it. Before I end this video, there's one thing I'd
like to do if I go back into Amazon s3, go inside my bucket and go into wherever we have permission
and go over bucket policy. Now for some of you that might be asking, Alright, so he just told
me to copy a policy, I have no clue how this work. I don't even know how I can generate my
own policy in the future. I have no clue what it is, I might not have the link you provide me and
so on. I want to get more details about this. Well, in case you guys want to generate your
own policy, if I go here and delete all of that, Amazon have this policy generator that you can
click on it, and it kind of give you this tool where you can generate your own custom policy.
So I can select the s3 bucket policy. And the effect is what type of access are you allowing
the people to do? Are you allowing them to do things? Are you denying them access to do things?
And the principle is a user or services or entity that you can allow access to certain things. For
this one, we're going to use the store. And I'm going to go all the way where we have the action,
I'm going to allow all the action for all get now you can select the specific action you want to
allow on this bucket. For my case, I'm going to select everything. And here, this is where things
can get a little bit tricky. Here, we're going to have to do with Amazon resource name. And what
that is, is it is a naming convention on how we can identify AWS resources. So how can we work
with this first thing first, we're going to copy this example right here. So I'm going to copy
this entire example right there. And here, we're going to remove this and specify our bucket name,
if you guys remember, our bucket name was YouTube demo s3. So I'm going to copy this one, right,
click and copy, go back to the policy generator, I'm going to replace this bucket name with the
name of my bucket. Again, all I do is we places the name with the bucket name, the next thing we
want to do is what files do we want them to access inside this bucket in here, I'm going to let them
access to everything that is inside this bucket. So I use the stock command right here to give them
access to everything that is inside my bucket and make sure that there's no space at the end of it.
Once you're done with that, make sure you click Add statement. And to generate the policy right
now, all I need to do is click on this button right there. And there you go, ladies and gentlemen,
my policy is generating, I can copy this one, right click copy, and go back to my policy,
paste them in there, save them and go back to my URL, wherever this is, we load this,
and it is still working as expected. Alright, this was a react application that we deploy to
Amazon s3. In the next video, we're going to see how we can deploy a Vue JS application into Amazon
s3. If this video has helped you in any ways, please do not leave without hitting the subscribe
button you help me me creating video like this for people like you to find and if you want to
stay tuned with every single new video that I release on this channel, definitely hit the
notification bell and turn all notification on. Thank you guys so much for watching this and see
you guys for the next video. Transcribed by https://otter.ai
