
Lesson Description
The "Running a DB Migration in ECS" Lesson is part of the full, Cloud Infrastructure: Startup to Scale course featured in this preview video. Here's what you'd learn in this lesson:
Erik runs the database migrations and deploys the service to the staging environment. He inspects the logs and discusses the metrics and monitoring available inside AWS. Erik also creates a `prod` branch off of `main` to highlight how deployments would be promoted from staging to production.
Transcript from the "Running a DB Migration in ECS" Lesson
[00:00:00]
>> Erik Reinert: So what I'm going to do actually is I'm going to run this locally. And so let's do this really quickly. Let's open up our GitHub actions here. And again, so it's ECS cluster name, ECS service name. So this is the command I'm going to run locally, right?
[00:00:24]
But what I'm going to do is I'm just going to say export ECS cluster name equals staging, right? And then. Not echo export, export and then export ECS service name equals ECS cluster name dash service. So if I do echo ECS and then cluster name, I've got my cluster name.
[00:00:58]
Then if I do echo ECSS service name, I should have staging service. Just so that we are all on the same page. Let's go back to our container service. If I go to staging staging service. Okay, cool. So that all looks good to me. So I'm going to click on staging service, go to tasks again, this is unhealthy and it's failing because we don't have our migrations ran.
[00:01:28]
So I'm going to do, I'm going to run that make command and let's see what happens. All right, so there we go. The task has been ran. So now we're waiting for the task to complete. Right now I should be able to go into here and actually go to just staging directly tasks and we'll see stopped.
[00:01:52]
Actually, let's go here. Created 23 seconds ago, stopped. Okay, cool. So it was successful. The migration ran. Awesome. Because we wouldn't have gotten to waiting for ECS service to stabilize if we hadn't gotten a successful code. But if I click on this, which was the task that ran, you'll see essential container in exit tasks or in task exited.
[00:02:18]
But it's not saying an error, it's just saying, hey, just to let you know, this successfully closed. If we go to logs, there they are, there's our migration logs. So if you wanna be able to see the migration, see the logs from the migration, all you have to do is go find that task ARN.
[00:02:37]
If we scroll up, so again, this is output from the actual successful task. A lot of it. But yeah, if we scroll up right here, you'll see tat running task. Here's the pending task. Task completed successfully with zero updating ECS service to use the latest task definition. We get our service information if we want to be able to debug it.
[00:03:00]
And now we're waiting for that service to stabilize. Now if I go to Tasks or if I go to staging, Staging service, we go to deployments. Hey, look at that. We're getting healthy. If we go to tasks here, we can see one running health and metrics. Look at that.
[00:03:21]
Healthy. Awesome. Now if we go back to our distribution, copy our URL. That might be the prod one, hang on. Okay. Yeah, this is the staging one. So grab this URL. Hey, we did it. So there you go. We now have a application running entirely on ECs behind a CDN on top of the image that we're running, configured by ssm.
[00:04:00]
And just really quickly, before we say anything else, I just want to again exemplify this is the same effect we had yesterday when App Runner ran. But the difference here again is the amount of effort and management required into getting a deployment like this running again. You saw the amount of terraform we had to create, the amount of knowledge we had to have understanding how to organize all this stuff and do all of it.
[00:04:31]
It's a lot of work. It is. Now what are the benefits here? As you sure also probably understand, there are tons of layers that you can control, manage, update, do whatever you need to. You have a lot more insight into what's running again, if I want to, I can go into where did my service thing go?
[00:04:53]
So if we go back into here, right, like if we want to talk about observability and metrics really quickly, like what do we have again, if we go into our vpc, we have the ability to look at VPC related metrics like networking and stuff like that. What else?
[00:05:10]
If we go in here we go to staging, we can see again, we can enable flow logs and things like that. If we go to our database rds, we can go and look at its metrics regarding again connections and you can start to see the other environment provisioning.
[00:05:29]
So we'll go in here, go to monitoring, we have all the monitoring related stuff which it's been running for a little while now. So we can actually see some metrics in here. The only one going up is my credit balance ECS as well. Ecs, we turned on container metrics or container insights.
[00:05:48]
If I go to staging, I click on a service, we could see some of the container insights here I can click on container insights and see even more utilization RX storage, read numbering of running tasks, all this stuff. So yeah, you're a lot deeper into it now, you're definitely a lot deeper into it.
[00:06:10]
Does it mean that the other one can scale better than this one? No, I mean, not necessarily. And does this mean that this one could scale way better than the other one? I mean, maybe a little bit, but not substantially to the point where it's going to be so massively impactful really quickly.
[00:06:28]
Again, what we would do after this is, okay, cool, we know that it's running. I'm gonna go ahead and add the make file changes, add the deploy changes, add all of this, and then do git commit_m feature added deployments to ecs. I'm going to push this up. This is now available to you guys.
[00:06:52]
So if you want to get access to this again, it's either in the stage three branch or in the workshop branch. But yeah, there we go. Now we've pushed it up. The moment I merged again, you've already seen deployments and how they work. What happens is we merge it to main, that's going to get deployed to the staging environment, like we said, because of the variable in the deploy script.
[00:07:15]
And then if it's on the production branch, which what we would do realistically is we would say, okay, I want to go into my main branch, I want to go to branches, I already created one, but here I'll do it anyways. Again, go in here, create a new branch off of Main, call it Prod, create that branch.
[00:07:37]
And now your deployment process will be work in your pr, work in your pr, work in your PR merge domain, that'll go to staging, merge domain, that'll go to Staging. And then once you go, okay, I'm ready to deploy, you take staging and then you just merge it into Prod.
[00:07:56]
Bam. All those changes get built, that gets deployed directly out to the Prod environment. Now, as we said before, what else we wanted to create was promotions in the sense of from one cloud environment to another. Now we can do that. Now we have complete control over those cloud environments.
[00:08:13]
We can deploy to them whenever we want, and then one URLs for our dev environment, one URLs for a production environment. You can even go further with this if you really wanted to. You could say, okay, let's get rid of the CDN and dev and then we'll only have the load balancer.
[00:08:28]
So dev's completely offline, or staging is completely offline, but have the production one completely set up like normal.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops