Coding

Deploying a Laravel App via Elastic Beanstalk | Amazon Web Services BASICS

  • 00:00:01 hi everyone welcome to this video my
  • 00:00:04 name is Maximilian and in a previous
  • 00:00:05 video I already got you started with AWS
  • 00:00:09 in this video I want to show you how you
  • 00:00:11 can deploy a level application including
  • 00:00:14 a database cue AWS using AWS elastic
  • 00:00:17 beanstalk let's start
  • 00:00:23 this is the application I want to deploy
  • 00:00:25 a very simple one but it does use a
  • 00:00:28 database behind the scenes in this
  • 00:00:30 application we can sign up
  • 00:00:36 and create blog posts like this is my
  • 00:00:40 first post the very first one when we
  • 00:00:47 did this we see an overview over all
  • 00:00:48 blog posts I already created some and
  • 00:00:51 that is the application not super
  • 00:00:53 amazing but using a database which makes
  • 00:00:56 it interesting when we talk about
  • 00:00:57 deployment now you can find this
  • 00:00:59 application on get up a link can be
  • 00:01:02 found in the video description and there
  • 00:01:04 you can simply clone or download this
  • 00:01:06 repository now I'll do this too so I
  • 00:01:10 will download it
  • 00:01:13 and I'll work with this one now as I
  • 00:01:17 said I want to use elastic beanstalk to
  • 00:01:19 deploy this application why if we switch
  • 00:01:22 to AWS in the end what we'll need is a
  • 00:01:25 server and we can spin up a virtual
  • 00:01:28 machine instance using their ec2 service
  • 00:01:32 this allows us to spin up virtual
  • 00:01:34 servers so basically like physical ones
  • 00:01:37 which we own but just a part on a
  • 00:01:39 physical server with the configuration
  • 00:01:40 we want we could do this and then we
  • 00:01:43 could install a web server on ec2 and
  • 00:01:46 deploy our code onto the instance we
  • 00:01:49 will also have to take care that we set
  • 00:01:52 it up in a secure way and do some
  • 00:01:54 configuration and we could do all that
  • 00:01:56 but there is an easier way if our goal
  • 00:01:59 is to deploy a web application and that
  • 00:02:01 easier way is an average service named
  • 00:02:04 elastic Beanstalk behind-the-scenes
  • 00:02:07 elastic Beanstalk will use easy to it
  • 00:02:10 will start such a server for us but it
  • 00:02:13 was you also all the other configuration
  • 00:02:15 we want to do and it makes it easy for
  • 00:02:16 us to ship our code onto the instance to
  • 00:02:19 manage different versions different
  • 00:02:21 environments like a testing or
  • 00:02:23 production environment and all these
  • 00:02:25 things well let's let's get started with
  • 00:02:28 elastic Beanstalk for that click simple
  • 00:02:31 you on get started and give your
  • 00:02:32 application a name I'll name it lateral
  • 00:02:35 simple block next you need to choose a
  • 00:02:38 platform and since we're using letter
  • 00:02:40 low this obviously should be PHP since
  • 00:02:42 levels and PHP framework we don't want
  • 00:02:45 to start the sample application instead
  • 00:02:47 we want to upload our own code and now
  • 00:02:50 it would be tempting to pick the zip
  • 00:02:53 file you downloaded from github right
  • 00:02:55 that won't work though the zip file
  • 00:02:57 which you upload here should contain all
  • 00:02:59 the source files and not a folder which
  • 00:03:03 contains all the source files therefore
  • 00:03:06 simply go to the folder you just
  • 00:03:08 download it and extract it this will
  • 00:03:12 give you a folder and now in this folder
  • 00:03:14 select all the files and compress them
  • 00:03:18 zip them again with your favorite
  • 00:03:20 zipping tool however before you do so
  • 00:03:23 make sure you do one thing you will see
  • 00:03:26 that dot Ian Vito
  • 00:03:27 sample file level managers a couple of
  • 00:03:30 global settings in its dot E&V file and
  • 00:03:33 by default this dot env fault is not
  • 00:03:36 shared when hosting or when shipping
  • 00:03:38 your code through a code repository like
  • 00:03:40 github which is why here you only have a
  • 00:03:42 dummy file and not an actual one you
  • 00:03:45 should copy that file and rename it to
  • 00:03:51 dot Ian we without dot example and now
  • 00:03:55 let's open that follows your favorite
  • 00:03:57 text editor I'm using sublime here and
  • 00:04:00 now you can edit it and one thing we do
  • 00:04:03 have to edit as we have to assign an app
  • 00:04:05 key here all the other settings can stay
  • 00:04:08 as they are for now I'll change this
  • 00:04:10 from local to brought though but this is
  • 00:04:12 up to you you can set any value here the
  • 00:04:15 URL can also stay as it is for now so we
  • 00:04:19 need that API key here the app key to be
  • 00:04:22 precise and to get one we can use the
  • 00:04:25 artisan command to generate one however
  • 00:04:28 for that we will need PHP installed in
  • 00:04:31 our machine so make sure that you have
  • 00:04:33 PHP installed you can then simply
  • 00:04:36 navigate into your folder and run PHP
  • 00:04:38 artisan and then a command but for this
  • 00:04:41 to work we actually need to do one our
  • 00:04:43 thing first we need to install all the
  • 00:04:45 dependencies if we have a look at our
  • 00:04:48 folder we see that it got no Wender
  • 00:04:51 folder here so all the dependencies
  • 00:04:53 including the lateral framework itself
  • 00:04:54 are missing that is normal you always
  • 00:04:57 distribute your code or ship it to get
  • 00:04:59 up with our dependencies like these
  • 00:05:01 since you can easily install them using
  • 00:05:03 composer in this case make sure you have
  • 00:05:06 composer installed on your machine link
  • 00:05:09 can be found in the video description
  • 00:05:10 and then in this project folder you
  • 00:05:12 downloaded and extracted you can run
  • 00:05:15 composer install and this will now
  • 00:05:18 install all the dependencies this
  • 00:05:20 project needs including level that will
  • 00:05:22 take a couple of seconds once it is done
  • 00:05:24 we can use the artisan command to
  • 00:05:26 generate a key
  • 00:05:28 so it did finish for me now you can run
  • 00:05:31 a new command still in that folder PHP
  • 00:05:34 artisan key : generate and this will
  • 00:05:38 generate this application key and
  • 00:05:39 automatically store it in this dot e + V
  • 00:05:42 file as you can see if you open it again
  • 00:05:45 here it is whether the project is
  • 00:05:48 prepared and now we can select all these
  • 00:05:51 files inside this folder so only the
  • 00:05:55 files in this folder and compress them
  • 00:06:00 this will generate a new zip file on
  • 00:06:02 windows of course use a program like sip
  • 00:06:05 or WinZip or WinRAR and whip that
  • 00:06:08 compressed you may take your compressed
  • 00:06:11 file rename it to whatever you like
  • 00:06:13 I'll name it Larry Wilson blog v1 and go
  • 00:06:18 cue elastic Beanstalk with it because
  • 00:06:21 here we need to upload our code and now
  • 00:06:23 we get a zip file with the code so let's
  • 00:06:25 choose the code here choose that zip
  • 00:06:28 file we just created which holds all our
  • 00:06:30 code including the dependencies
  • 00:06:31 including the vendor folder and let's
  • 00:06:33 click upload now as you can see in the
  • 00:06:36 bottom left is now ships our code to
  • 00:06:38 Amazon then elastic Beanstalk will spin
  • 00:06:41 up the ec2 instance we need and we'll
  • 00:06:43 ship our code onto the instance and also
  • 00:06:45 configure that instance to hold a
  • 00:06:47 webserver and so on before it does
  • 00:06:50 although we need to go through the
  • 00:06:51 remaining steps of the configuration we
  • 00:06:53 could click create application or we
  • 00:06:56 have a view look at the other options we
  • 00:06:58 can set up here we can for example
  • 00:07:01 choose which kind of fries that we want
  • 00:07:03 to use
  • 00:07:03 I'll go up the low-cost one which stays
  • 00:07:06 within this free tier as long as you
  • 00:07:08 don't have multiple of these apps but of
  • 00:07:09 course you could choose to a more
  • 00:07:11 production-ready one and you can change
  • 00:07:14 the environment settings I'll name the
  • 00:07:16 environment here differently I'll name
  • 00:07:18 it prod you can choose any name you like
  • 00:07:21 and you can manage different environment
  • 00:07:23 on the elastic Beanstalk for example for
  • 00:07:25 a testing environment a protection
  • 00:07:27 environment a staging environment new
  • 00:07:29 feature environment whatever you need
  • 00:07:31 now with this all set up the default
  • 00:07:35 settings should be fine and we can click
  • 00:07:38 on create app now this will
  • 00:07:42 as such assets been up that ec2 instance
  • 00:07:44 ship or occurred onto it set everything
  • 00:07:46 up there and I'll be back once that's
  • 00:07:48 finished the environment successfully
  • 00:07:51 launched for me and with that we get a
  • 00:07:53 link where you can visit our application
  • 00:07:55 so let's click it and there we see
  • 00:07:58 forbidden now do you have an idea where
  • 00:08:01 this error might come from it's tricky
  • 00:08:04 to spot but do you have an idea well you
  • 00:08:08 find out where this error comes from
  • 00:08:11 let's have a look at our level
  • 00:08:12 application structure this is the folder
  • 00:08:15 we uploaded and there as you probably
  • 00:08:18 are aware if you know a level the main
  • 00:08:21 entry point where the request is handled
  • 00:08:24 first is inside the public folder here
  • 00:08:27 we get said index.php file which is
  • 00:08:29 responsible for getting any incoming
  • 00:08:31 requests and then funneling it through
  • 00:08:33 the level framework you could say now we
  • 00:08:37 uploaded this whole folder to Beanstalk
  • 00:08:40 and therefore Beanstalk shifted to our
  • 00:08:42 web server on ec2 on this virtual server
  • 00:08:45 the issue is the incoming request
  • 00:08:47 therefore it doesn't hit the public
  • 00:08:49 folder it hits this folder the whole
  • 00:08:51 folder and there we simply don't handle
  • 00:08:54 it this is in the end the reason for
  • 00:08:57 this error we can easily change this
  • 00:08:59 though let's go to the configuration of
  • 00:09:02 our environment of the Prada environment
  • 00:09:04 here and there under software
  • 00:09:06 configuration we can configure anything
  • 00:09:08 related to our server which is running
  • 00:09:10 here so if you click on this Settings
  • 00:09:13 icon
  • 00:09:14 we can set a document root and this is
  • 00:09:17 exactly what we need here here we can
  • 00:09:19 decide from which folder from which
  • 00:09:22 subfolder the server should in the end
  • 00:09:25 serve our fuzz or where the request
  • 00:09:28 should basically be handled and we can
  • 00:09:31 set this to slash public so that now we
  • 00:09:35 target the public folder and there it
  • 00:09:37 will then automatically you reach the
  • 00:09:39 index.php file with this tiny change we
  • 00:09:43 will fix this error now what else can
  • 00:09:45 you configure here a couple of service
  • 00:09:48 specific settings about compression for
  • 00:09:50 example if you want to display errors
  • 00:09:52 and until when you want to or when you
  • 00:09:55 want to terminate incoming requests and
  • 00:09:58 some settings about logging now we don't
  • 00:10:00 need that but this public thing here is
  • 00:10:03 really interesting with that let's click
  • 00:10:05 apply here and this will update our
  • 00:10:09 environment now this operation takes a
  • 00:10:11 couple of seconds we can still reach our
  • 00:10:13 application during that timeframe most
  • 00:10:15 of the time at least but then at some
  • 00:10:17 point it will restart the web server and
  • 00:10:19 after that if we visit the application
  • 00:10:21 again this looks much better
  • 00:10:24 unfortunately the next issue isn't far
  • 00:10:27 away if we click on register and try to
  • 00:10:30 register here we get an error we get in
  • 00:10:36 sequel error that the connection was
  • 00:10:38 refused and this makes sense we're
  • 00:10:42 trying to connect your database in the
  • 00:10:43 level code but we got no database here
  • 00:10:46 by default no database is created on
  • 00:10:49 that virtual server wishes spun out by
  • 00:10:51 elastic Beanstalk behind the scenes now
  • 00:10:54 we could install a server on this ec2
  • 00:10:57 instance by the way you can always have
  • 00:10:59 a look at this instance by simply going
  • 00:11:01 to the ec2 service and they're under
  • 00:11:04 instances you see that there's one
  • 00:11:06 running instance this is the one which
  • 00:11:08 was spun up by elastic Beanstalk so we
  • 00:11:12 can see that here and as I said we could
  • 00:11:15 install a database on my sequel database
  • 00:11:17 for example on that instance but the
  • 00:11:20 issue we would then have is that we have
  • 00:11:22 to fully manage that database it then
  • 00:11:25 runs on our own server we have to backed
  • 00:11:28 data up we have to make sure that we are
  • 00:11:30 protected against failures if the server
  • 00:11:33 for some reason goes down if we ever
  • 00:11:36 want to switch the hardware or upgrade
  • 00:11:39 to a bigger server we'll have to do
  • 00:11:41 everything about that switch on our own
  • 00:11:43 so we have to fully manage the database
  • 00:11:45 and that is a huge disadvantage for big
  • 00:11:48 enterprises that's of course doable and
  • 00:11:51 pretty common but for you there is a
  • 00:11:53 much simpler way of quickly adding a
  • 00:11:56 database to your stack let's go to
  • 00:11:59 configuration again
  • 00:12:00 and as you can see we are in the web
  • 00:12:03 tier or here are a couple of options
  • 00:12:05 related to the
  • 00:12:06 so to our website you could say now if
  • 00:12:09 we scroll down you see there always a
  • 00:12:11 data here and here we don't see any
  • 00:12:13 options as of now but we can attach a
  • 00:12:16 database to our elastic beanstalk
  • 00:12:19 environment here we can create a new RDS
  • 00:12:22 database and RDS stands for relational
  • 00:12:25 database service
  • 00:12:27 it's another service provided by AWS
  • 00:12:30 which allows us to spin up database
  • 00:12:32 instances so database servers with a
  • 00:12:35 configuration of our choice again
  • 00:12:37 regarding the power and then with
  • 00:12:40 database on these servers now this is a
  • 00:12:43 fully managed service so here we don't
  • 00:12:45 have to take care about backing the data
  • 00:12:48 up or updating software that's all done
  • 00:12:51 by AWS and they're always a free tier
  • 00:12:53 option available here so that we even
  • 00:12:55 don't pay a dime for the first year as
  • 00:12:57 long as again we stay in some boundaries
  • 00:13:00 as set on the pricing page by AWS so
  • 00:13:04 let's click create a new RDS instance
  • 00:13:05 and we're taking to this wizard here we
  • 00:13:08 could create this instance based on an
  • 00:13:10 existing snapshot which would basically
  • 00:13:12 copy old data into this to be created
  • 00:13:16 database I don't want that I want to
  • 00:13:18 start with a blank database we can
  • 00:13:20 choose the DB engine and I'll go with my
  • 00:13:22 sequel here now a sequel is included in
  • 00:13:26 the free tier and the version of the
  • 00:13:27 engine as you can see we get a couple of
  • 00:13:30 different versions five point six point
  • 00:13:32 two nine three four three five or six
  • 00:13:34 two six point two nine the instance
  • 00:13:37 classes are really big one here I'll
  • 00:13:39 scale this sound to t2 micro to stay in
  • 00:13:42 the fridge here and then we have to set
  • 00:13:44 up a root username and password with
  • 00:13:47 which we can access this database server
  • 00:13:49 I'll choose root here and also a
  • 00:13:53 password now here I just set up to
  • 00:13:57 automatically create a snapshot if the
  • 00:13:59 database server is ever going to get
  • 00:14:01 shut down so that the data is safe the
  • 00:14:04 fourth shuts down and that we don't want
  • 00:14:06 to copy that cross-multiply bill ability
  • 00:14:08 zones which is fine for this example
  • 00:14:11 with that let's hit apply and now it is
  • 00:14:13 the starting and mute database instance
  • 00:14:16 using that RDS service
  • 00:14:18 and on that database instance so on this
  • 00:14:20 database server it will also
  • 00:14:22 automatically create a new database this
  • 00:14:25 will take a couple of minutes but once
  • 00:14:28 this is starting up we can already think
  • 00:14:30 about a new issue we have to solve in
  • 00:14:33 our environment in our application if we
  • 00:14:37 have a look at the dot and fall which
  • 00:14:39 again manages our settings here we see
  • 00:14:44 that the database connection is set up
  • 00:14:46 by default it uses the local host
  • 00:14:48 database username these are all settings
  • 00:14:51 for our local development environment
  • 00:14:53 for whom sted specifically in this case
  • 00:14:56 obviously these values are not correct
  • 00:14:59 if we use the database host it on some
  • 00:15:01 server created or managed by AWS now
  • 00:15:05 instead we will have to enter the host
  • 00:15:08 so the address of this database server
  • 00:15:10 then the name of the exact database on
  • 00:15:13 that server and our credentials now I
  • 00:15:16 could already enter the credentials we
  • 00:15:18 just set up in a couple of seconds ago
  • 00:15:21 actually but it would be nice if there
  • 00:15:23 would be a more dynamic way of getting
  • 00:15:25 access to these values in the end
  • 00:15:28 elastic beanstalk is managing everything
  • 00:15:30 and it turns out it also gives you
  • 00:15:33 access to the database settings on the
  • 00:15:36 server superglobal how does that work we
  • 00:15:40 can go to the config folder in a lateral
  • 00:15:43 project and there we have this database
  • 00:15:44 PHP file in here we manage the
  • 00:15:47 configuration for the database and if we
  • 00:15:50 open this again with any text editor of
  • 00:15:52 your choice
  • 00:15:53 you see that here we can configure which
  • 00:15:56 default connections used you see that's
  • 00:15:58 my sequel and then for that connection
  • 00:16:00 things like the host the port the
  • 00:16:03 database username and password and these
  • 00:16:05 are exactly these things
  • 00:16:06 we need to define all you need to pass
  • 00:16:09 now outside of this return statement at
  • 00:16:12 the beginning of the file we can now
  • 00:16:14 define a couple of Global's the first
  • 00:16:18 one could be named RDS hostname and the
  • 00:16:20 name here is totally up to you you can
  • 00:16:22 name this globe whatever you like the
  • 00:16:24 value is not up to you though here we
  • 00:16:26 should access our server superglobal
  • 00:16:29 and on that superglobal we have the RDS
  • 00:16:33 hostname very low property we can access
  • 00:16:36 this property is populated by elastic
  • 00:16:40 Beanstalk in the end it passes us this
  • 00:16:42 value with every incoming request so
  • 00:16:45 that we have a chance of dynamically
  • 00:16:48 retrieving our database value and
  • 00:16:50 accessing the database and whenever we
  • 00:16:53 change something about the database we
  • 00:16:55 therefore don't you to adjust our
  • 00:16:56 lateral code so that is the hostname I
  • 00:17:00 need more than that
  • 00:17:02 for example we also want to adjust the
  • 00:17:05 user name here or get the user name and
  • 00:17:08 we can get this on this server
  • 00:17:10 superglobal and there on the user name
  • 00:17:12 property RDS username then we want to
  • 00:17:15 extract the password and we want to get
  • 00:17:17 this too and now where is this request
  • 00:17:20 is of course not sent from your client
  • 00:17:22 this is something LS it Beanstalk passes
  • 00:17:24 your application once the request is
  • 00:17:26 basically or has reached the backend
  • 00:17:29 already so this is not exposed to any
  • 00:17:31 users and finally the name of the
  • 00:17:34 database this is a database created by
  • 00:17:36 being stalked we have no idea what its
  • 00:17:38 naming it and here we can simply
  • 00:17:41 retrieve it without having to worry
  • 00:17:42 about the name with these clothes setup
  • 00:17:45 we can go down and for example here
  • 00:17:48 replace the host with the RDS host name
  • 00:17:50 global which will host the host the
  • 00:17:53 database here can be released with the
  • 00:17:55 DB name and the username obviously with
  • 00:17:58 the username whilst we can set the
  • 00:18:01 password well equal to RDS password
  • 00:18:05 whoops
  • 00:18:06 RDS password here with this this
  • 00:18:09 database PHP file is prepared and it's
  • 00:18:12 now able to well retrieve that data or
  • 00:18:16 that information dynamically and
  • 00:18:18 therefore connect to the database that's
  • 00:18:21 not all we all need to change something
  • 00:18:25 else remember that we could only choose
  • 00:18:27 for or between database my sequel
  • 00:18:30 versions 5.6 something we couldn't
  • 00:18:34 choose 5.7 and level 5.4 the version I'm
  • 00:18:39 using here actually requires my sequel 5
  • 00:18:42 point
  • 00:18:43 seven or higher or a certain command at
  • 00:18:46 the point of time we run migrations will
  • 00:18:48 fail we can already set this up too and
  • 00:18:51 DISA Stan in the app folder under
  • 00:18:55 providers under app service provider
  • 00:18:58 there if you open that file you should
  • 00:19:01 first use schema here at the top to
  • 00:19:05 import that schema pass aid and then in
  • 00:19:07 the boot function simply execute schema
  • 00:19:10 and there the default string length
  • 00:19:15 method method and set it to 191 this
  • 00:19:19 will overwrite the default level
  • 00:19:21 otherwise assumes which is not possible
  • 00:19:23 when using or which will lead to an
  • 00:19:25 error when using an older my sequel
  • 00:19:27 database version as we're doing as we're
  • 00:19:30 forced to do in our Beanstalk app with
  • 00:19:33 this command however we will prevent
  • 00:19:35 this from happening it leads us to a new
  • 00:19:38 issue though or a new thing we have to
  • 00:19:40 think about migrations if we were to
  • 00:19:43 deploy our code to our server right now
  • 00:19:46 we would probably be able to connect to
  • 00:19:49 the database but what do you have to do
  • 00:19:51 the first time you set up your level
  • 00:19:54 application on a server be that your
  • 00:19:56 development environment or the
  • 00:19:57 production environment you have to run
  • 00:20:00 your migrations because of course in
  • 00:20:03 this project too I set up a couple of
  • 00:20:06 migrations here in the database
  • 00:20:07 migrations folder one for the user's
  • 00:20:10 table and one for the posts table and we
  • 00:20:12 have to run these migrations right at
  • 00:20:14 the start when you deploy this app for
  • 00:20:16 the first time to make sure that these
  • 00:20:19 tables are created in the database
  • 00:20:21 otherwise nothing will work now for that
  • 00:20:24 we can run the PHP artisan migrate
  • 00:20:26 command but how do we run that command
  • 00:20:28 on a server which is not on our local
  • 00:20:32 machine there are different ways of
  • 00:20:34 doing it you could connect to this ec2
  • 00:20:37 instance which it was created by
  • 00:20:39 Beanstalk via SSH you could set up an
  • 00:20:43 SSH connection and then manually execute
  • 00:20:46 this command in the lateral folder on
  • 00:20:48 the server that is doable on Windows you
  • 00:20:51 will need extra gab program or
  • 00:20:53 application to run SSH though
  • 00:20:55 a different alternative or generally an
  • 00:20:59 alternative is to take advantage of
  • 00:21:01 behavior or elastic Beanstalk offers to
  • 00:21:04 you you can create a new folder here in
  • 00:21:07 your project and name this dot EB
  • 00:21:12 extensions
  • 00:21:15 now the name is important it should have
  • 00:21:16 a leading dot and it should be named EB
  • 00:21:18 extensions after the dot inside that
  • 00:21:22 folder you now can create files which
  • 00:21:24 have to end with dot config which will
  • 00:21:28 be run by elastic Beanstalk
  • 00:21:30 every time you deploy a new version and
  • 00:21:33 therefore here I can simply create a new
  • 00:21:37 file when we first enter container
  • 00:21:40 underscore commands and this is not
  • 00:21:44 something you can choose this as a
  • 00:21:45 command or a setup a configuration
  • 00:21:48 basically detected by elastic Beanstalk
  • 00:21:50 then indent with a tab we're using the
  • 00:21:54 yamo format here and add a name of the
  • 00:21:57 command this is now again totally usable
  • 00:21:59 by you the commands you list here will
  • 00:22:02 be executed in alphabetical order though
  • 00:22:04 and more information about this file can
  • 00:22:06 be found in the link in the video
  • 00:22:07 description all name is 0-1 in it DB :
  • 00:22:13 again indent and then here command : and
  • 00:22:17 then the command between double
  • 00:22:19 quotation marks which you want to
  • 00:22:21 execute and this will be PHP artisan
  • 00:22:24 migrate this will now migrate all your
  • 00:22:27 fault
  • 00:22:28 make sure to implement this fix I showed
  • 00:22:31 a couple of seconds ago before you run
  • 00:22:33 this so this fix regarding the default
  • 00:22:35 string length and what's that you can
  • 00:22:37 now save this file
  • 00:22:40 in your root project folder a name it
  • 00:22:44 for example in it config now course make
  • 00:22:51 sure to in the end place it in the study
  • 00:22:57 be extensions folder here and with that
  • 00:23:00 disk file look at executed by elastic
  • 00:23:02 beanstalk and the command in there will
  • 00:23:04 be executed to thus migrating our files
  • 00:23:07 now of course it will execute us
  • 00:23:09 whenever you deploy a new version too so
  • 00:23:12 for newer versions you should probably
  • 00:23:13 not include that because migrate would
  • 00:23:15 fail then since the database tables
  • 00:23:17 already would exist and that is why
  • 00:23:20 connecting Y is SH and running the
  • 00:23:22 command by doing this or by well having
  • 00:23:25 that connection might be the preferable
  • 00:23:27 way for such one-time-only tasks like
  • 00:23:31 this one but I want to show this
  • 00:23:33 capability r2 and of course there are a
  • 00:23:35 couple of ways of automating this whole
  • 00:23:37 elastic beam stuff proces even more for
  • 00:23:39 example with the elastic Beanstalk CLI
  • 00:23:42 back to our example your though we can
  • 00:23:45 switch back to the elastic Beanstalk
  • 00:23:47 console and it just finished here and
  • 00:23:49 with that we can go back and create a
  • 00:23:53 new bundle we want to deploy
  • 00:23:54 so let's first delete the old one and
  • 00:23:58 then select everyone here everything
  • 00:24:01 here and compress it again this again
  • 00:24:05 will take a couple of seconds and this
  • 00:24:06 new sip for now has to be deployed again
  • 00:24:08 I'll first rename it to letter ville
  • 00:24:11 simple blog video but the name is
  • 00:24:14 totally up to you and back in the
  • 00:24:16 elastic Beanstalk console you can now
  • 00:24:18 click on upload and deploy to upload a
  • 00:24:20 new application version here I'll choose
  • 00:24:24 this new file which holds the changes
  • 00:24:27 regarding the dynamic database
  • 00:24:28 connection this initialization script
  • 00:24:30 and this fixed for lateral 5.4 with
  • 00:24:34 older my sequel databases and we can now
  • 00:24:37 hit deploy this will now upload the code
  • 00:24:40 again and then exchange to code the old
  • 00:24:42 code with this new one whilst doing that
  • 00:24:45 it will not restart the ec2 instance or
  • 00:24:48 anything like that so we can still
  • 00:24:49 access our application while it's doing
  • 00:24:51 that but after a couple of second
  • 00:24:53 the new code will be live and can be
  • 00:24:56 used by us it already finished let's
  • 00:24:59 click this file here and let's now try
  • 00:25:02 this registration again I'll again enter
  • 00:25:05 my email address here and my password
  • 00:25:08 and click register and I get a
  • 00:25:10 connection refused error well it's kind
  • 00:25:15 of deceiving if we have a look at the
  • 00:25:17 fraud environment we see this ok at this
  • 00:25:19 check mark and everything looks great
  • 00:25:21 but actually if we scroll down we see
  • 00:25:23 that it failed to deploy the application
  • 00:25:26 so it simply didn't update the code it
  • 00:25:29 rolled back to our old application code
  • 00:25:31 now this error can be really strange at
  • 00:25:34 first it looks like we messed something
  • 00:25:36 up in our agamas and tells us invalid
  • 00:25:38 llamo but actually this is related to
  • 00:25:41 how mac and you can see a hint here
  • 00:25:43 stores hidden folders even though we
  • 00:25:46 can't see it here there is like extra
  • 00:25:48 subfolder in there you can simply fix
  • 00:25:52 this error or this strange behavior by
  • 00:25:54 going into the terminal into that folder
  • 00:25:56 so where it is zip file can be found in
  • 00:26:00 executing set – d wearable symbol block
  • 00:26:04 the zip file and then underscore
  • 00:26:07 underscore mac OS x /e x slash start and
  • 00:26:12 this will remove this annoying folder in
  • 00:26:16 there with this out of the way we can
  • 00:26:20 try uploading this again so let's choose
  • 00:26:23 this zip file again now we have to
  • 00:26:26 define our own version label since the
  • 00:26:28 old one is already taken since you
  • 00:26:31 already tried it with the same filename
  • 00:26:33 from which is infer set and now let's
  • 00:26:35 see if that works so let's wait for this
  • 00:26:39 to finish uploading and now hopefully it
  • 00:26:42 again it will replace our application
  • 00:26:44 code this time hopefully successfully
  • 00:26:46 and hopefully it now is successful
  • 00:26:49 running this initialization command
  • 00:26:51 setting up our database and adding the
  • 00:26:54 tables in there now that looks much
  • 00:26:57 better
  • 00:26:57 let's visit our web page again and let's
  • 00:27:00 try this registration process here again
  • 00:27:03 now we're forwarded now it seems to
  • 00:27:06 successfully
  • 00:27:07 user there's already hit the database
  • 00:27:09 and at center post and see if that all
  • 00:27:13 the works and it does now we get the
  • 00:27:16 application working on elastic Beanstalk
  • 00:27:18 with a dynamic connection to the
  • 00:27:20 database as you saw there were some
  • 00:27:23 gotchas we had to take care about as I
  • 00:27:25 mentioned there are of course more
  • 00:27:27 flexible or better ways of deploying
  • 00:27:30 everything through the elastic Beanstalk
  • 00:27:31 CLI you can automate a lot of the stuff
  • 00:27:34 you saw here but this is how you can
  • 00:27:36 ship your applications and there is
  • 00:27:37 nothing wrong about this approach so if
  • 00:27:40 you got a lateral application which you
  • 00:27:41 want to host this is how you could do it
  • 00:27:44 and for the first year as long as you
  • 00:27:46 don't use any other services at least
  • 00:27:48 this will be for free that is how that
  • 00:27:52 works in another with you I want to take
  • 00:27:54 a closer look at elastic beanstalk and
  • 00:27:57 what we can do any configuration what
  • 00:27:59 all just stop on the lectures about
  • 00:28:02 hopefully see you there bye