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 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
版本: 2024.10 剛剛發布