Welcome back to backspace Academy in this hands-on session I'm going to 2
demonstrate how to use the Elastic Beanstalk service to launch multiple 3
environments and then use those multiple environments in a Blue Green deployment 4
to update our code, okay so starting off in the Elastic Beanstalk management 5
console this time I'm going to go to the top right-hand side here and click on 6
create new application, we'll just give our application a name and click on 7
create and so that will create a base Elastic Beanstalk application and we can 8
create environments that are associated with that application 9
we'll do that now, so we just go to actions and create environment 10
it's a web server environment and we'll leave the environment name or we give it 11
environment - one that's fine now platform will be NodeJS and we're 12
still again going to just use a sample application and we're not going to 13
configure any more options we just want to launch this to a single instance 14
to make it quite quick and easy, so we'll create that environment, now while that 15
environment is creating, we'll just jump back into our blue-green application and 16
I'm going to create another environment 17
and we'll call this one environment - 2 and exactly the same as before 18
a nodejs application and again we'll use the sample application as before and we 19
won't configure any more options and we'll create an environment so we have 20
two identical environments that will be launched right now okay so after quite a 21
few minutes we're going to have our second environment up and running and if 22
we click on the URL for that environment we can see there we've got our AWS 23
sample code for nodejs if we go back into our application here our blue-green 24
application we can see our two environments, we click on our 25
environment they've created we should be seeing the same thing as well and that's 26
fine so what we need to do now is go back into our application and we look at 27
application versions and so there we can see is that the AWS sample application 28
has been deployed to both of these environments over here so environment 1 29
environment two so what I'm going to do is I'm going to download that so I 30
just click on that and that'll take us to the documentation and we can download 31
the sample nodejs application from there so I'll just click on that and download 32
that now after I've downloaded and extracted that zip file what I can do 33
then is that I can look at modifying this code so I'm just going to open up 34
this index.html and just going to edit it in notepad and it's going to scroll 35
down to where it says the text column and I'm just going to change the 36
background color of that to it's currently green I'm just going to change 37
that to the blue and then save that and then what I'm going to do is to zip that 38
back up again so I just select everything and see if that's so what I 39
can do now so I can upload that updated code to Elastic Beanstalk and we should 40
have a blue application going there, so I'm going to do that to the second 41
environment, so I click on the environments tab here and I'll select 42
the second environment and I'm going to upload and deploy our new code so I'll 43
just click on that I'll choose that file 44
and deploy that now after a certain amount of time we're going to have that 45
deployed on our second environment but I'll give it a try now if I click on 46
this endpoint we hopefully have a blue yes we have a blue background there now 47
so we changed our code we updated that to the second environment and there we 48
can see that it has come through fine if we go back to our first environment that 49
will still be green so just say that we have our domain name that is pointed to 50
this endpoint here and what we want to do is that we want to we don't want to 51
go into route 53 and change CNAMEs and whatever and muck around like that we 52
just want a very quick way to swap over from our production environment to our 53
development environment and then make our development environment our 54
production environment and so the quickest way to do that is is with 55
Elastic Beanstalk by doing a URL swap and it'll swap the URL for this 56
environment to the other environment so then your domain that is being pointed 57
to this URL will alter all of a sudden be pointed to the other environment so 58
let's give that a go. So what we do is we go into actions and then we do swap 59
environment URLs so that's going to just swap this endpoint here for the 60
endpoint of the other environment so we slick their environment number two is 61
that the environment that we want to swap to and we click on swap and that 62
will take a while to happen so after a few minutes we're going to see that the 63
the URLs for these two environments have swapped so now our environment number 64
one which was which had our green background is now going to be pointing 65
at at the URL that was previously for environment number two we can see 66
they're in - - now we go to the second environment 67
so remember this is the environment that had the blue background it is now 68
pointing or is our using the URL for the first environment so if we've got our 69
domain name pointed to this URL here now that means that all of a sudden we're 70
going to get the updated code and it's going to happen instantaneously so we 71
click on that we should get a blue background and there we go so we have 72
our environment one or that was our originally our environment one URL is 73
now pointing to the environment number two which has our blue background so 74
that's how a Bluegreen deployment works and obviously our environment number one 75
or our original environment will now become our development environment and 76
vice versa and so that's the way it works so what we can do now is that we 77
can clean this all up and again we go to all applications and delete that 78
application and delete so it'll delete the application and it would delete 79
those two environments as well so we get his check on that we can see that the 80
determinating those environments so that brings us to the end of a pretty long 81
hands-on session I don't expect you to do this yourself it's not a lab because 82
there's quite a little bit going on here but it's good to understand exactly how 83
a Bluegreen environment works I look forward to seeing you in the next one