Managing AWS Lambda Concurrency Settings with AWS CDK

Understanding AWS Lambda Concurrency

Concurrency in AWS Lambda refers to the number of invocations of a Lambda function that can run simultaneously. By default, AWS Lambda functions have a concurrency limit of 1000, but you can configure this limit to suit your needs. Controlling concurrency is crucial for ensuring the efficient and reliable execution of your serverless applications.

Using AWS CDK to Set Concurrency

The AWS CDK is a development framework for defining cloud infrastructure in code. It allows you to define and provision AWS resources using familiar programming languages. To set the concurrency for a Lambda function using the CDK, you typically use the reservedConcurrentExecutions property when defining the Lambda function. Here’s an example in TypeScript:

const lambdaFunction = new lambda.Function(this, ‘MyLambdaFunction’, {
// other Lambda function configurations
reservedConcurrentExecutions: 10, // Set the concurrency to 10
});

In this example, we’ve set the concurrency limit to 10 for the Lambda function MyLambdaFunction.

Manually Changing Concurrency

Sometimes, you might need to manually modify the concurrency settings of a Lambda function using the AWS Management Console. However, it’s essential to understand that changes made manually in the console do not automatically sync with your CDK code.

Modifying Code vs. Manul Concurrency Settings

It’s important to note that changing the code of your Lambda function and redeploying it using the AWS CDK does not automatically revert any manually changed concurrency settings in the AWS Lambda console. The CDK manages the deployment of your code and the desired state of your infrastructure, but it doesn’t actively monitor or manage the current state of resources.

Reverting Concurrency Settings

If you’ve manually changed the concurrency settings in the AWS Lambda console and want to revert them to the values specified in your CDK code, you need to do the following:

  1. Modify your value in CDK code to set the reservedConcurrentExecutions property back to the desired value (e.g., 11 or 9 in our example).
  2. Redeploy your CDK stack.

After following these steps, the Lambda function’s concurrency settings will be updated to the value specified in your CDK code.

AWS SQS Message deduplication on FIFO

Message deduplication for FIFO (First-In-First-Out) queues is a process in messaging systems that ensures that duplicate messages are identified and removed from the queue before being processed. In a FIFO queue, the order in which messages are received is maintained, meaning the first message sent into the queue will be the first one processed.

Message deduplication helps prevent situations where identical messages are processed multiple times, which can lead to unintended consequences or duplicate actions. This is especially important in scenarios where processing duplicate messages could cause data inconsistencies or other issues.

When a message is sent to a FIFO queue, the system typically uses a unique identifier, called a deduplication ID, to determine whether the message is a duplicate or not. If a message with the same deduplication ID is already in the queue, the new message is considered a duplicate and is either discarded or not added to the queue.

This mechanism ensures that only unique messages are processed, maintaining the order of messages in the queue and preventing unnecessary duplication of work or actions.

Example:

Let’s consider an e-commerce website that uses a FIFO queue to process orders. The system receives order requests from customers and places them in a FIFO queue for processing. To avoid processing the same order multiple times, message deduplication is implemented.

  1. Customer A submits an order for a laptop, and the system generates a unique order ID, let’s say “Order123”. The order request, along with the deduplication ID “D123”, is added to the FIFO queue.
  2. Customer B also submits an order for the same laptop shortly afterward. The system generates a different order ID, such as “Order124”, but since the order details (including the laptop model) are identical, the deduplication ID “D123” is used again.
  3. Before adding Customer B’s order to the queue, the system checks the deduplication ID “D123”. Since a message with the same deduplication ID is already in the queue (from Customer A’s order), the system recognizes this as a duplicate order and does not add it to the queue again.
  4. Later, Customer C submits an order for a different item, a smartphone. This order is assigned a unique order ID “Order125”, and a new deduplication ID “D125” is generated.
  5. Customer D places an order for the same smartphone shortly afterward. Again, the order details are the same, so the deduplication ID “D125” is used for this order as well.
  6. The system checks the deduplication ID “D125” and sees that there is already a message with this ID in the queue (from Customer C’s order). Like before, it identifies the duplicate and does not add Customer D’s order to the queue.

By implementing message deduplication, the system ensures that even though duplicate orders were attempted (from Customers B and D), only the original orders (from Customers A and C) are processed. This helps maintain order accuracy and prevents unintended duplication of actions, improving the overall reliability of the order processing system.

Flutter is getting popular…

In recent days flutter is being popular among developers, you know why

I would say because it’s open source , so that the documentation and tutorials are cooked by massive community in world wide with no limitations.

Here are some of key features that attract techies

  • build apps quickly and efficiently
  • Most one is “hot reload” feature enables developers to instantly see the changes they make to the code, which speeds up the development process.
  • Smooth animation, its use of Dart language and its advanced rendering engine
  • Be a UI legend , pre-designed widgets makes it easy to create beautiful, customizable, and responsive user interfaces (UI) for mobile apps. So you don’t have to be expiry on UI.
  • Cross-platform – write once and deploy across Android, iOS, and web

Happy Learning

Kick started 2023 and learned till 2022

After a long time, writing back to the blog 😌 making me more relaxed , the past 5 years give me so many good things and though me so many things to learn life as no stop of learning life.I would the good things are

The most valuable person I got in my life is equally, actually more supportive as my mother is my wife Gomathi Manikandan(kulfi).

And one of the best company in my professional experience is FOODHUB (T2S) same as first company Nuveda Learning . Of course, I stepped into my marriage life and T2S at the same time. And experienced unexpected & excited travelling.

Achieved my AWS solution architect as refreshment on AWS carrier. Got so many good people.

Life though me that we don’t need to worry about the delay or things we are waiting to happen might be come with late but much better. As I addressed above are a couple of examples.

Even if things did not happen well , we should be who we are and never try to change yourself, do good things as were doing. It could be family, professional or any things.
Because as humans we do things differently at different times based on our situation, but the other way around we forgot to remain that change is the only constant, and those who embrace it will thrive.

Learning as lesson on this great year starting with ,
As Heraclitus, a Greek philosopher, said “Change is the only constant in life” so embrace it.

Hopefully I will keep posting the changes here as

Great things happen to those who don’t stop believing, trying, learning, and being grateful.

Multiple Django 2 Site on Appache 2

apache vhsot site 1

<VirtualHost *:80>
ServerName abc.site.com
WSGIDaemonProcess abcsite python-path=/djangopath1 python-home=/djangopath1/env
WSGIScriptAlias / /djangopath1/master_api/wsgi.py
WSGIProcessGroup abcsite
<Directory /djangopath1/master_api>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /djangopath1/>
WSGIProcessGroup abcsite
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

apache vhsot site 2

<VirtualHost *:80>
ServerName xyz.site.com
WSGIDaemonProcess xyzsite python-path=/djangopath2 python-home=/djangopath2/env
WSGIScriptAlias / /djangopath2/master_api/wsgi.py
WSGIProcessGroup xyzsite
<Directory /djangopath2/master_api>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /djangopath2/>
WSGIProcessGroup xyzsite
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

Deploy angular build in Apache

Normally Apache will through error,like when try to access http://localhost/login , apache will try to load folder called login.

To make this work , we can write rule in .htaccess as below

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ – [NC,L]
RewriteRule ^(.*) index.html [NC,L]

Make use you have enabled the rewire module in Apache.

And if you your using any folder in Apache like http://localhost/sub-folder/login, you have to specify the path while build the project as $ng build –base-href /sub-folder/

Django admin css not loading

When I have moved my project from MAC to windows, the admin page style are broken.
The css files are trying to load as admin/admin/css/….
so I have to specify the static config in settings.py as blow
old

STATIC_URL = os.path.join(BASE_DIR, ‘static/’)

new
STATIC_URL = ‘/static/’

STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)

Now it looks good , no idea how it works on Linux with old config 🙂