DEV Community

Awwal
Awwal

Posted on

Deploying Text to Image App on ECS

Lets start by creating a cluster. Cluster

  1. Go to the Amazon ECS service page. Click clusters to create a new cluster. ECS cluster

Give your cluster what ever name you like
We leave other options as default.
Scroll to the bottom and click create
Click create cluster

  1. Creating Task Definition Task definition

Click task definitions on the left menu.
On the task definition screen click on create new task definition
We will use an already built docker image on Amazon ECR (Elastic Container Registry) to save time. link to git page of the streamlit app code
Under Container 1 use the public image URI public.ecr.aws/o3s1z9h7/build-on-poster:latest

Give your task definintion a name
Naming task definition

Leave the rest of the pages configuration as default, scroll to the bottom and click Next.
Under Environment variables click Add environment variable button.
For Variable Name use
IMAGE_API and TEXT_API

Since we are utilizing code from someone else’s public container image, it is essential that our variable names align with those used in the code. Let’s create two variables: one to call our stable diffusion lambda function and the other for Text Summarization lambda function.

Adding variables

Adding Variable names and values

Leave the remaining configurations as default, scroll to the bottom and click Next.

Go to the IAM service page or scroll to Task roles above Task role click the link to the IAM console to navigate to the page (to grants permission to containers enabling them interact with other AWS services).
Select create role on the IAM page
Leave the defaults select elastic container registry for service below. Then scroll down click next

Creating IAM role

Under services select Elastic container registry
Navigating to Elastic container registry

In the Add permissions page search for and select AmazonECSTaskExecutionRolePolicy

Add permission page select AmazonECSTaskExecutionRolePolicy

Clear filter after selecting AmazonECSTaskExecutionRolePolicy.

Search for lambd_fullAccess and select it. To grant ECS containers unrestricted access to our lambda functions.
Click Next

Attach policy AWSLambda_FullAccess

Give your role any name

Naming Role

Scroll to the bottom click create role.

After successful Role creation we move back to ECS Task definition and select our newly created role under Task role.

Select our recently created role

You can turn off cloudwatch log collection under Logging to save cost.

turn of cloudwatch monitoring

Click Next below to proceed

Review
Review and create Task Definition

Review and create Task Definition continued

Click create below

Running A Task with Our Task Definition

On the left menu click cluster

Navigate to clusters

Click the cluster you created earlier on the cluster page

Select recently created cluster

Click Tasks tab as shown above, then click the Run new task button

Running the Task

On the create task page.

Compute Configuration

Under Compute configuration, select Launch type as your compute option to keep things simple.

Under Deployments select the task definition we just created using the drop down as shown below.

Selecting Task definintion

Under Networks
We could either edit our default security group to allow inbound traffic or create a new one which does. We would create a new one.
Select create a new security group under security group

creating sec groups contd

Give your security group a name
Give your security group any description.

describing sec group

For inbound rules under Type select HTTP
For Source select "Anywhere"
Also ensure the Public IP button is toggle On, so we know our IP address and connect to it.

Leave Task overrides as default

Edit container overrides
We copy the output url of the lambda functions we created in the previous post to summarize text and the function to convert text to image as values of our container environment variables.

Copy image to text func url

Copy the Function url of both functions and paste them into container IMAGE_API and TEXT_API values.
One at a time

Copy and use the function url text summary as environment variable

Use function url of diffusion function as value of IMAGE_API and the function url of text_summary function as value of TEXT_API.
Click save button to run task. After pasting function url your enviroment variables should like the image below.

dipiction on env var under container overrides

Test your site
Under Tasks click your task when it gets to the Running state

Click Tasks to test site

Scroll down on the task page
Under Configuration setting
Click the public url

clicking public url

It displays loads our site on a new page

dipiction of our site

Lets test it
paste or write an article to be summarized and converted to text

cloud house

You can use an article here

image from text from aws community article

Top comments (0)