|
| 1 | +--- |
| 2 | +sidebar_position: 2 |
| 3 | +--- |
| 4 | + |
| 5 | +# AWS App Runner 🏃 |
| 6 | + |
| 7 | +[App Runner](https://aws.amazon.com/apprunner/) is a fully managed service that makes it easy for developers to quickly deploy containerized web applications and APIs, at scale and with no prior infrastructure experience required. It is service in [Amazon Web Services](https://aws.amazon.com/). App Runner automatically: |
| 8 | + |
| 9 | +- Load balances traffic with encryption |
| 10 | +- Scales to meet your traffic needs |
| 11 | +- Makes it easy for your services to communicate with other AWS services and applications that run in a private Amazon VPC |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +Before you get started, if you haven't already completed these steps, you'll have to: |
| 16 | + |
| 17 | +1. Create a free [Amazon Web Services account](https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-creating.html) |
| 18 | + |
| 19 | +:::caution |
| 20 | +While Amazon Web Services has a free tier that should cover testing projects, you can incur costs when running this quickstart through App Runner or Elastic Container Registry. For more details, see [AWS App Runner Pricing](https://aws.amazon.com/apprunner/pricing/) and [Amazon Elastic Container Registry Pricing](https://aws.amazon.com/ecr/pricing/). |
| 21 | +::: |
| 22 | + |
| 23 | +2. Install [Docker](https://docs.docker.com/get-docker/) on your machine, and you'll have to start the app. You can verify it is set up correctly by running: |
| 24 | + |
| 25 | +```bash |
| 26 | +docker images |
| 27 | +``` |
| 28 | + |
| 29 | +(If Docker is running, the command will print the images on your machine. If not, it will print something like `Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?`) |
| 30 | + |
| 31 | +3. Install the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) on your machine. |
| 32 | + |
| 33 | +4. [Configure the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html) to give it permission to push images. Just make sure the user you configure has the `AmazonEC2ContainerRegistryFullAccess` policy applied. |
| 34 | + |
| 35 | +5. Give Docker permission to push images to AWS by running: |
| 36 | + |
| 37 | +```bash |
| 38 | +aws ecr get-login-password --region [REGION] | docker login --username AWS --password-stdin [AWS_ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com |
| 39 | +``` |
| 40 | + |
| 41 | +- `[REGION]`: The region you want to deploy to (ex: us-west-1) |
| 42 | +- `[AWS_ACCOUNT_ID]`: The id of the account you're deploying to, without dashes (can be found in the top right menu) |
| 43 | + |
| 44 | +6. Create a private Elastic Container Registry (ECR) Repository. This can be done [in the AWS Console](https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-create.html), or by running: |
| 45 | + |
| 46 | +```bash |
| 47 | +aws ecr create-repository --repository-name [REPOSITORY_NAME] |
| 48 | +``` |
| 49 | + |
| 50 | +- `[REPOSITORY_NAME]`: A name for the newly created repository. |
| 51 | + |
| 52 | +## Deploying |
| 53 | + |
| 54 | +1. Build your API for production use by running: |
| 55 | + |
| 56 | +```bash |
| 57 | +dart_frog build |
| 58 | +``` |
| 59 | + |
| 60 | +This will create a /build directory with all the files needed to deploy your API. |
| 61 | + |
| 62 | +2. Build your API using Docker by running: |
| 63 | + |
| 64 | +```bash |
| 65 | +docker build build \ |
| 66 | + --tag [AWS_ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/[REPOSITORY_NAME]:[IMAGE_TAG] |
| 67 | +``` |
| 68 | + |
| 69 | +- `[REGION]`: The region you want to deploy to (ex: us-west-1) |
| 70 | +- `[AWS_ACCOUNT_ID]`: The id of the account you're deploying to, without dashes (can be found in the top right menu) |
| 71 | +- `[REPOSITORY_NAME]`: The name of the repository you created eariler |
| 72 | +- `[IMAGE_TAG]`: A name given to this image to identify it in the repository |
| 73 | + |
| 74 | +This command will build the Docker image on your computer and can take a few seconds to a few minutes. |
| 75 | + |
| 76 | +3. Push the image to ECR by running: |
| 77 | + |
| 78 | +```bash |
| 79 | +docker push [AWS_ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/[REPOSITORY_NAME]:[IMAGE_TAG] |
| 80 | +``` |
| 81 | + |
| 82 | +You should now see your repository in the [ECR console](https://console.aws.amazon.com/ecr) |
| 83 | + |
| 84 | +4. Create your App Runner service following [these instructions](https://docs.aws.amazon.com/apprunner/latest/dg/manage-create.html#:~:text=Create%20a%20service%20from%20an%20Amazon%20ECR%20image). Look for the `Create a service from an Amazon ECR image` section. |
| 85 | + |
| 86 | +5. Congratulations! 🎉 You have successfully built and deployed your API to App Runner. You can now access your API at the Default domain on the [App Runner console](https://console.aws.amazon.com/apprunner) |
| 87 | + |
| 88 | +## Additional Resources |
| 89 | + |
| 90 | +- [What is AWS App Runner?](https://docs.aws.amazon.com/apprunner/latest/dg/what-is-apprunner.html) |
| 91 | +- [Managing custom domain names for an App Runner service](https://docs.aws.amazon.com/apprunner/latest/dg/manage-custom-domains.html) |
| 92 | +- [Viewing App Runner logs](https://docs.aws.amazon.com/apprunner/latest/dg/monitor-cwl.html) |
0 commit comments