IronWorker CaaS Worker: AWS Fargate Setup
In this article, we will tell you the steps you need to set up AWS Fargate for IronWorker.
Achieve Cloud Elasticity with Iron
Speak to us to find how you can achieve cloud elasticity with a serverless messaging queue and background task solution with free handheld support.
1. Store Docker Image on ECR
In order to deploy the docker image of our application we need to push it to ECR (Elastic Container Registry) AWS service for storing containers, it works like pushing source code to GitHub. We need to create a new repository by navigation to ECR in AWS Console - ECS and click the “Create Repository” button.
Next will enter a repository name, keep everything as the default unless required to change. Click the “Create Repository” button to continue
After this step, you should get your ECR repository created with a set of instruction on how to connect and push your docker image to the repository
Click on “View push commands” on top to view the commands set
This step requires AWS CLI v2 installed and configured. Find more about getting started with ECR and AWS click here https://docs.aws.amazon.com/AmazonECR/latest/userguide/getting-started-cli.html
1. Connect to ECR repository
2. From inside the application directory at the Dockerfile level will build the docker image.
docker build -t xe-alert-repository .
3. Now tag the created image
4. Push to ECR repository
docker tag xe-alert-repository:latest
Clicking on the repository name will list all image tags. Click “Copy URI” to get the image URI for the next steps of creating the cluster and the tasks.
2. Creating the Task Definition
ECS Task definition defines the container details of our application.
Click on “Task Definition” from the left menu then click the “Create new Task Definition” button.
Select Fargate Lunch Type and click Next.
Next, we will be specifying container details name, container, ports, IAM role..etc
Set Task definition name, memory, and CPU then click on “Add container” to specify container image details.
Set container name, enter ECR Image URI from the previous step of pushing our application docker image to ECR.
Set ports container exposed ports. I use port 3000 for the NodeJs server inside the container.
The last thing to add on this screen is the environment variables we need to use inside our containerized application.
Optional step if you want to specify volumes to load within the container you can manage in the following section.
Now we are ready to create our Task definition, click “Create”
Now we have successfully created the task definition.
Iron.io Serverless Tools
Speak to us to learn how IronWorker and IronMQ are essential products for your application to become cloud elastic.
3. Create the ECS Cluster
At this point, we will create a new ECS Cluster by selecting the “Powerd by AWS Fargate” Template.
Enter a cluster name, check “Create VPC” and check “Enable Container Insights” for Cloudwatch monitoring.
Click “Create” and wait for few minutes as this step creates a punch of resources for us and may take several minutes.
After finishes, we are done with creating the cluster and will move next to create our service worker using the created definition on this newly created cluster.
4. Create Task service
From inside our cluster details page select the “services” tab and click on “Create”
At this screen, we will configure our service to run on the cluster and to load the container image from the Task definition we created earlier.
Select the launch type as “Fargate” select the task definition and the revision (image tag) you which to use, the cluster option should be the created cluster, enter the service name, and a number of tasks to run.
Go to the next step to configure the network options.
On the network configuration screen select at least one subnet, and click the “Edit” button to enable the container port “3000” on the VPC security group.
Keep everything else as default in the Auto Scaling screen unless you need to setup a load balancer.
procced to the review page and click “Create Service”.
After finishes successfully within the cluster details page select the service name then select the “Tasks” tab.
On the task details, it will show the public IP address of the running task will use that to send a get request to our Nodejs app server running on port 3000.
It Works! And the SMS message has been delivered to the registered phone number.
One more optional option to mention is scheduling the task run, to achieve that you need to create a new task definition revision and set the container environment variable “autoRun” to equal “TRUE” and follow the steps as we did with creating the service inside the cluster.
Give the scheduled rule a name, set running interval you can choose the “corn expression” option to set unix-cron expression.
Select the new revision with updated Environment Variable “autoRun”.
Select the VPC or create a new one, make sure the security group exposes the port 3000.
You can confirm or override container environment variables at the last option.
Number of tasks per region per account: 20 Max size of docker image: 4 GB
Max Container Storage size: 10 GB
Fragate Quotes & Limites:
AWS Fargate is compliant with PCI DSS Level 1, ISO 9001, ISO 27001, ISO 27017, ISO 27018, SOC 1, SOC 2, SOC 3, and HIPAA
7. AWS Fargate Cost
AWS Pricing for Fargate is calculated for CPU and Memory usage duration.
Like every other AWS service pricing is different between regions, the following example will be for us-east-1 (N. Virginia) region.
Pricing per vCPU and Memory is:
vCPU per hour = $0.04048 = $0.000011244 per second Memory GB per hour = $0.004445 = $0.000001235 per second
vCPU per second = $0.04048 / 3600 = $0.000011244 Memory GB per second = $0.004445 / 3600 = $0.000001235
If we are going to run our XE-Currency-Alert application for 30 days with a scheduled task to run every 30 minutes, knowing avg worker compute time is 22 seconds, each task uses 0.25 vCPU and 0.5 GB RAM our monthly cost breakdown will be.
Monthly CPU charges
Total vCPU charges = # of Tasks x # vCPUs x price per CPU-second x CPU duration per day (seconds) x # of days
Total vCPU charges = 48 x 0.25 x 0.000011244 x 22 x 30 = $0.08905248
Monthly memory charges
Total memory charges = # of Tasks x memory in GB x price per GB x memory duration per day (seconds) x # of days
Total memory charges = 48 x .5 x 0.000001235 x 22 x 30 = $0.0195624
Monthly Fargate compute charges
Monthly Fargate compute charges = monthly CPU charges + monthly memory charges
Monthly Fargate compute charges = $0.08905248 + $0.0195624 =
Leave a Comment