入门指南 AWS Copilot 由 部署一个 Amazon ECS 应用 - Amazon Elastic Container Service
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

如果我们为英文版本指南提供翻译,那么如果存在任何冲突,将以英文版本指南为准。在提供翻译时使用机器翻译。

入门指南 AWS Copilot 由 部署一个 Amazon ECS 应用

AWS Copilot 按照 AWS 服务条款作为预览计划进行管辖。

通过在 GitHub 中联系我们来报告 AWS Copilot 的问题,在这里您可以开设问题、提供反馈和报告错误。

了解如何部署 Amazon ECS 应用,使用 AWS Copilot.

Prerequisites

开始之前,先完成以下前提条件:

部署您的应用程序 使用一个命令

确保您安装并运行了ASM的命令线工具 aws configure 然后再开始。

使用下列命令部署应用程序。

git clone git@github.com:aws-samples/amazon-ecs-cli-sample-app.git demo-app && \ cd demo-app && \ copilot init --app demo \ --svc api \ --svc-type 'Load Balanced Web Service' \ --dockerfile './Dockerfile' \ --port 80 \ --deploy

部署您的应用程序 逐步

步骤1: 配置 您的凭证

运行 aws configure 设置默认配置文件, AWS Copilot CLI 将用来管理您的应用程序和服务。

aws configure

步骤2: 完成演示 应用程序

克隆一个简单的面具应用程序和Dockerfile。

git clone git@github.com:aws-samples/amazon-ecs-cli-sample-app.git demo-app

步骤3: 设置您的 应用

  1. 在演示应用程序目录中,运行 init 命令。

    copilot init

    AWS Copilot 引导您完成您的 首先 应用程序和服务 有一系列终端 提示,从 下一步. 如果 您已经使用 AWS Copilot 来部署应用程序,系统会提示您 从应用程序名称列表中选择一个。

  2. 命名您的应用程序。

    What would you like to name your application? [? for help]

    Enter demo.

步骤4: 设置您的 ECS应用程序服务

  1. 系统会提示您选择服务类型。您正在构建一个简单的 为小型API提供服务的面具应用程序。

    Which service type best represents your service's architecture? [Use arrows to move, type to filter, ? for more help] > Load Balanced Web Service Backend Service

    Choose Load Balanced Web Service.

  2. 请提供服务的名称。

    What do you want to name this Load Balanced Web Service? [? for help]

    Enter api 对于 您的服务名称。

  3. 选择Dockerfile。

    Which Dockerfile would you like to use for api? [Use arrows to move, type to filter, ? for more help] > ./Dockerfile

    Choose Dockerfile.

  4. 定义端口。

    Which port do you want customer traffic sent to? [? for help] (80)

    Enter 80 或 接受默认值。

  5. 您将看到一个日志,显示应用程序资源 已创建。

    Creating the infrastructure to manage services under application demo.
  6. 创建应用程序资源后,部署测试 环境。

    Would you like to deploy a test environment? [? for help] (y/N)

    Enter y.

    Proposing infrastructure changes for the test environment.
  7. 您将看到一个日志,显示您的申请状态 部署。

    Note: It's best to run this command in the root of your Git repository. Welcome to the Copilot CLI! We're going to walk you through some questions to help you get set up with an application on ECS. An application is a collection of containerized services that operate together. Use existing application: No Application name: demo Service type: Load Balanced Web Service Service name: api Dockerfile: ./Dockerfile no EXPOSE statements in Dockerfile ./Dockerfile Port: 80 Ok great, we'll set up a Load Balanced Web Service named api in application demo listening on port 80. ✔ Created the infrastructure to manage services under application demo. ✔ Wrote the manifest for service api at copilot/api/manifest.yml Your manifest contains configurations like your container size and port (:80). ✔ Created ECR repositories for service api. All right, you're all set for local development. Deploy: Yes ✔ Created the infrastructure for the test environment. - Virtual private cloud on 2 availability zones to hold your services [Complete] - Virtual private cloud on 2 availability zones to hold your services [Complete] - Internet gateway to connect the network to the internet [Complete] - Public subnets for internet facing services [Complete] - Private subnets for services that can't be reached from the internet [Complete] - Routing tables for services to talk with each other [Complete] - ECS Cluster to hold your services [Complete] - Application load balancer to distribute traffic [Complete] ✔ Linked account aws_account_id and region region to application demo. ✔ Created environment test in region region under application demo. Sending build context to Docker daemon 74.24kB Step 1/2 : FROM nginx ---> 9beeba249f3e Step 2/2 : COPY index.html /usr/share/nginx/html ---> Using cache ---> c685b776e459 Successfully built c685b776e459 Successfully tagged aws_account_id.dkr.ecr.region.amazonaws.com/demo/api:cee7709 WARNING! Your password will be stored unencrypted in /home/user/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded The push refers to repository [aws_account_id.dkr.ecr.region.amazonaws.com/demo/api] 592a5c0c47f1: Pushed 6c7de695ede3: Pushed 2f4accd375d9: Pushed ffc9b21953f4: Pushed cee7709: digest: sha_digest ✔ Deployed api, you can access it at http://demo-Publi-1OQ8VMS2VC2WG-561733989.region.elb.amazonaws.com/api.

步骤5: 检验您的 应用程序正在运行

使用下列命令查看应用程序状态。

列出您的所有 AWS Copilot 应用程序。

copilot app ls

显示有关您环境中的环境和服务的信息 应用程序。

copilot app show

显示有关您的环境的信息。

copilot env ls

显示有关服务的信息,包括端点、容量和相关 资源。

copilot svc show

应用程序中的所有服务列表。

copilot svc ls

显示已部署服务的日志。

copilot svc logs

显示服务状态。

copilot svc status

列出可用的命令和选项。

copilot --help
copilot init --help

步骤6: 清洁 向上

运行下列命令以删除和清理所有资源。

copilot app delete --env-profiles test=default