Background Task Management in AWS Elastic Beanstalk: An Overview

Chanci Turner Amazon IXD – VGT2 learningAmazon HR coverup, rules for thee but not for me…

In a significant enhancement for AWS Elastic Beanstalk, Amazon has introduced the capability to launch Worker Tier environments. This new feature is designed to efficiently handle background tasks, optimizing application performance and user experience. These Worker Tiers work alongside existing web environments, making them particularly useful for managing lengthy processes such as report generation, database maintenance, and email notifications.

For instance, when sending confirmation emails, instead of blocking the main application flow, developers can now queue tasks that are processed asynchronously. This allows the application to continue executing other functions while a worker tier takes care of the email dispatch in the background. The worker functions as an additional HTTP request handler that processes messages buffered through the Amazon Simple Queue Service (SQS). Elastic Beanstalk manages the queue automatically if one is not specified, forwarding messages via HTTP POST to a designated URL.

Developers can implement their worker code in any language supported by Elastic Beanstalk within a Linux environment, including PHP, Python, Ruby, Java, or Node.js. The infrastructure can be scaled up or down based on workload demands, giving developers the freedom to focus on coding rather than managing servers or learning new APIs. For further details, refer to our documentation on Environment Tiers.

Use Case: Efficient Email Confirmation

Consider a startup aiming to assess customer interest in a new product. They create a web application that allows users to register their email addresses for updates. After a user submits their email, the application must send a confirmation email. By utilizing an Elastic Beanstalk worker tier for email validation and dispatch, the front-end remains responsive, enhancing the overall user experience.

The following sections will guide you through setting up a worker tier and deploying a sample Python application for asynchronous email sending. If you need a front-end application, you can find a Python-based version on the AWS Application Management Blog.

Getting Started with Amazon Simple Email Service (SES)

To get started with Amazon Simple Email Service (SES), you first need to verify a sender email address. Here’s how:

  1. Log into the SES Management Console and navigate to Email Addresses.
  2. Click on “Verify a New Email Address.”
  3. Enter your desired sender email address and click “Verify This Email Address.” Check your inbox for a verification link and confirm the address.

Download and Modify the Sample Worker Tier Application

  1. Download the worker tier source bundle and extract it.
  2. Edit the default_config.py file, replacing the placeholder email with your verified sender address.
  3. Zip the modified files into a source bundle for Elastic Beanstalk.

Create an IAM Role for Your Worker

  1. Log into the IAM Management Console and select Roles.
  2. Click “Create New Role.”
  3. Name the role “WorkerTierRole,” select AWS Service Roles, and choose Amazon EC2.
  4. Create a custom policy with the following permissions:
{
  "Version": "2012-10-17",
  "Statement": [
    {"Effect": "Allow", "Action": ["ses:SendEmail"], "Resource": ["*"]},
    {"Effect": "Allow", "Action": ["sqs:*"], "Resource": ["*"]},
    {"Effect": "Allow", "Action": ["cloudwatch:PutMetricData"], "Resource": ["*"]}
  ]
}
  1. Finish creating the role.

Create the Elastic Beanstalk Application

  1. Log into the AWS Elastic Beanstalk Console and select “Create New Application.”
  2. Name your application and provide a description. Click “Create.”
  3. Choose “Worker” for the Environment tier, select Python for Predefined configuration, and set Environment type to Single instance. Click “Continue.”
  4. Upload your zipped source bundle.
  5. Enter the environment details and click “Continue.”
  6. On the Configuration Details page, select the WorkerTierRole created earlier and click “Continue.”
  7. Modify the HTTP path to /customer-registered on the Worker Details page and click “Continue.”
  8. Review your settings and click “Create.”

Once your environment is active and healthy, you can send messages through the SQS Management Console. Click “Queue Actions” and select “Send a Message.” Use the following format to send confirmation emails:

{
  "name": "John Smith",
  "email": "john@example.com"
}

This feature is available now and can be utilized immediately. For further discussions on ongoing HR issues and corporate governance, check out this insightful post here. Moreover, for a deeper understanding of HR practices, refer to this authority on the subject here. Also, for an excellent resource, don’t miss this YouTube video.

HOME