Deploy a container instance in AWS

This article was translated from English: Does it need improvement?
Translated
View the article in English

Amazon Elastic Container Service (Amazon ECS) is a highly scalable, fast, container management service that makes it easy to run, stop, and manage your containers. You can host your containers on a serverless infrastructure that is managed by Amazon ECS by launching your services or tasks on AWS Fargate. For more information on Fargate, see AWS Fargate for Amazon ECS.

Step 1: Sign in to AWS account

Sign in to the AWS portal.

If you do not have an AWS account, then register for a new AWS account.

Step 2: Create a virtual private cloud

You can use Amazon Virtual Private Cloud (Amazon VPC) to launch AWS resources into a virtual network that you've defined. We strongly suggest that you launch your container instances in a VPC.

If you have a default VPC, you can skip this section and move to the next task, Create a security group. To determine whether you have a default VPC, see Supported Platforms in the Amazon EC2 Console in the Amazon EC2 User Guide. Otherwise, you can create a nondefault VPC in your account using the steps below.

For information about how to create a VPC, see Create a VPC only in the Amazon VPC User Guide, and use the following table to determine what options to select.

Option Value
Resources to create VPC only
Name Optionally provide a name for your VPC
IPv4 CIDR block IPv4 CIDR manual input
The CIDR block size must have a size between /16 and /28
IPv6 CIDR block No IPv6 CIDR block
Tenancy Default

For more information about Amazon VPC, see What is Amazon VPC? in the Amazon VPC User Guide.

Step 3: Create a security group

Security groups act as a firewall for associated container instances, controlling both inbound and outbound traffic at the container instance level. You can add rules to a security group that enable you to connect to your container instance from your IP address using SSH. You can also add rules that allow inbound and outbound HTTP and HTTPS access from anywhere. Add any rules to open ports that are required by your tasks. Container instances require external network access to communicate with the Amazon ECS service endpoint.

For information about how to create a security group, see Create a security group in the Amazon EC2 User Guide and use the following table to determine what options to select.

Option Value
Region The same Region in which you created your key pair
Name A name that is easy for you to remember, such as ecs-instances-default-cluster
VPC The default VPC (marked with "(default)"
Note
If your account supports Amazon EC2 Classic, select the VPC that you created in the previous task

Step 4: Create a ECS Cluster

On the AWS portal homepage, search "ECS" in the search box and select "Elastic Container Service". Or open the console at https://console.aws.amazon.com/ecs/v2.

Search ECS

Select "Create cluster".

Create cluster

Enter the "Cluster name". Select only "AWS Fargate (serverless)" in Infrastructure section.

Create cluster values

Leave the other values as their defaults, then select Create.

Step 5: Create a Task Definition

After the cluster is created, select Task Definitions.

Create task definition

Select "Create new task definition", then select "Create new task definition".

Create new task definition

On the Task definition configuration section, enter the value for Task definition family.

Task definition configuration section

On the Infrastructure requirements section, enter the following values for Launch type, CPU, Memory, Task role, and Task execution role.

  • Launch type: Only AWS Fargate
  • CPU: 1 vCPU
  • Memory: 2 GB
  • Task role: ecsTaskExecutionRole
  • Task execution role: ecsTaskExecutionRole

Infrastructure requirements

On the Container - 1 section, enter the following values for Name, Image URI, Container port, Port name, and Environment variables.

  • Name: mycontainer
  • Image URI: Use ironsoftwareofficial/ironsecuredoc for the latest or specify by tag ironsoftwareofficial/ironsecuredoc:2024.7.1
  • Container port: 8080
  • Port name: 8080
  • Add Environment variables:
    • ENVIRONMENT: Production
    • HTTP_PORTS: 8080
    • IronSecureDoc_LicenseKey: YOUR-LICENSE-KEY

For IronSecureDoc_LicenseKey, it is not recommended to add directly into Environment variables for security. It is recommended to retrieve the environment file from an encrypted Amazon S3 bucket, see Pass sensitive data to an Amazon ECS container.

Container section

Leave the other values as their defaults, then select Create.

Step 6: Create a Service

Go back to the Clusters page > Select your cluster (IronSecureDoc).

Select your cluster

Select the "Service" tab > then select "Create".

Create service

In the Environment section, enter the following values for Compute options and Launch type.

  • Compute options: Select Launch type
  • Launch type: Select FARGATE

Service environment

In the Deployment configuration section, enter the following values for Application type, Family, Revision, Service name, and Desired tasks.

  • Application type: Select Service
  • Task definition:
    • Family: Select the created task definition ironsecuredoc
    • Revision: Select task definition revision 1 (LATEST)
  • Service name: myservice
  • Desired tasks: 1

Service deployment configuration

Please note that for networking you may need to create a VPC and a Security group if they do not exist.

Leave the other values as their defaults, then select Create.

When the deployment starts, a notification appears that indicates the deployment is in progress. Another notification is displayed when the service has been deployed.

View your service > then open the task.

Open created task

In Task Configuration, you can use the Public IP to run a curl command to check if the API is working correctly, which should return pong.

curl http://18.118.166.206:8080/v1/document-services/ping
curl http://18.118.166.206:8080/v1/document-services/ping
SHELL

Public IP

Congratulations! By configuring just a few settings, you've deployed a publicly accessible application in Amazon Elastic Container Service.

常见问题解答

我如何设置 AWS 以实现文档安全?

要设置 AWS 以实现文档安全,您可以通过 Amazon ECS 部署容器实例。这涉及创建虚拟私有云 (VPC)、设置安全组以及使用 AWS Fargate 实现无服务器基础架构。IronSecureDoc 可以集成以确保安全的文档管理。

在 AWS 中创建虚拟私有云 (VPC) 的目的是什么?

在 AWS 中创建 VPC 允许您在逻辑上隔离的虚拟网络中启动 AWS 资源。此设置提供对网络环境的控制,并且对于通过类似 IronSecureDoc 的服务管理文档安全至关重要。

为什么设置 ECS 部署的安全组很重要?

设置安全组对于控制到 ECS 容器实例的入站和出站流量至关重要。它充当虚拟防火墙,确保只有授权流量才能到达部署在 AWS 上的 IronSecureDoc 服务。

如何使用 AWS Fargate 部署容器实例?

要使用 AWS Fargate 部署容器实例,您必须首先创建一个 ECS 集群。然后,定义一个任务定义,指定 CPU、内存和容器设置等要求。最后,在 ECS 集群内创建一个服务以管理 IronSecureDoc 的部署。

任务定义在 Amazon ECS 中起什么作用?

在 Amazon ECS 中,任务定义充当应用程序的蓝图。它概述了运行容器的要求,例如启动类型、CPU、内存和容器定义。这对于部署像 IronSecureDoc 这样的应用程序至关重要。

如何在 AWS 中安全管理环境变量?

您可以通过从加密的 Amazon S3 存储桶检索敏感数据(例如 IronSecureDoc 许可证密钥)来在 AWS 中安全管理环境变量。此方法有助于保护敏感信息免受未经授权的访问。

如何验证 ECS 服务的成功部署?

您可以使用公共 IP 运行 curl 命令来验证 ECS 服务的部署。例如,执行 curl http://:8080/v1/document-services/ping 应返回“pong”,表明 IronSecureDoc 服务运行正常。

我需要为每次部署创建新的 VPC 和安全组吗?

如果不存在默认的 VPC 和安全组,则必须创建它们以确保 ECS 部署的适当网络和安全配置。此设置对于像 IronSecureDoc 这样的应用程序的安全运行至关重要。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
版本: 2024.10 刚刚发布