[Music]
welcome to back to basics
i am gerardo estaba and today we're
going to talk about deploying your code
have you ever deployed your code
nervously i know i have back in the day
before the cloud and modern software
development practices
i remember the adrenaline rush of
manually logging into a server
running my deployment scripts and just
hoping that it works
and i remember many of those going wrong
or upsetting our users for a long period
of time because we broke the system
and also scrambling trying to roll those
changes back
fortunately in the cloud we don't have
to deploy with this level of uncertainty
thanks to modern software development
practices and services
that allow us to automate code
deployments
so let's start with an example the
simplest architecture i can think of
a single amazon ec2 instance running
your code
but how can we deploy new code to this
instance
well i can of course connect manually
into the instance and run my deployment
scripts
however by doing this i'm risking
something going wrong
with my code or the script and
potentially disrupting my users
and bring that bring back those hurtful
memories
of manual rollbacks because even if you
tested your code in a development server
there's always a chance that the
production server is different
this is what's called mutual
infrastructure
perhaps someone logged in updated or
changed something
and forgot to update the development
server so your deployment
in one mutable server may behave
differently in another
mutable server it happens
so how can we implement control changes
so that our running code
can be changed in a predictable manner
we can do this with an immutable
infrastructure
because within mutual infrastructure no
changes happen
in the production server for example
with two instances we can have one
instance for deployment
while the other one keeps serving the
traffic
an easy way to ensure availability and
performance of multiple instances
serving traffic
is using auto scaling one of the
beautiful things of auto scaling is that
it automates instance creation
for example by having pre-baked amazon
machine images or amis
because these amis include the operating
system we need
and all the software packages needed to
run my application
with auto scaling when an instance fails
or we have an
increase in traffic more instances are
quickly created
based on the pre-baked ami
so now that we have our application
running on our autoscaling group
how do we deploy code into it in a
control way
well to minimize risk of deployment and
maybe errors
i'm going to suggest that we use
automation there are many great tools to
help with this for our example we're
going to use aws code deploy
this is a service that makes it easy to
automate code deployments but
maintaining your application uptime
code deploy is very easy to use you need
to set it up by installing the agent and
configuring your deployment
configuration and then
you can start creating deployments
pointing code deploy to your code
that's it but cod deploy also has a
couple of mechanisms to help us mitigate
deployment risks
for example configuring at one at a time
in place deployment
means that code deploy will deploy the
code only to one instance in our auto
scaling group
and only after that seems successful
will it deploy to another one
one at a time you can see how this
gradual process makes deployment much
safer
another way of mitigating risk of
deployment is by deploying
to parallel environments this is
sometimes called blue green deployment
codeploy also allows us to choose blue
green deployments
with this code deploy provisions a new
autoscaling group
let's call it the green environment by
copying the original one
that we call the blue environment then
code deploy will deploy the new
application revision onto the green
environment and once the deployment is
successful
code deploy can reroute the traffic code
deploy also helps us automate testing
to make sure that our deployment
actually work and
automate rollback in case it didn't this
help us minimize
recovery time but also manual errors
we can achieve this by using code deploy
pre-deployment or
and plus deployment triggers that for
example
allow you to trigger a lambda function
to do functional tests
go the ploy can automatically roll back
when the deployment fails
or when that lambda function returns an
error
or when a cloudwatch alarm is flagged
so there you have it nervous deployments
are a thing of the past
if you use immutable infrastructure
perhaps with auto scaling
and you automate your deployments
perhaps with aws code deploy
you can get a lot of peace of mind when
deploying code see you next time