“Dude Where Are My Resources?” Using Serverless to Manage Your Resources

Tom Brovender
Develeap
Published in
3 min readJan 23, 2023

Previously, we discussed the use of AWS Lambda and Serverless frameworks, which can be found here.

A common follow-up question that we received to that article is, “What if I need to use a resource within my Serverless configuration?” As when we want to provision said resources, most people go straight to using Terraform or any other IAC and input the needed names into the serverless configuration, but the power of serverless comes from its own resource management.

In a serverless architecture, dependent resources are any resources that are required by a serverless function to perform its intended task, such as databases, message queues, or any other services. These resources are typically managed separately from the serverless framework and may be hosted on different services, such as AWS RDS or SQS. It is the responsibility of the developer to properly configure and manage these dependent resources, such as setting up security, scaling, and monitoring.

In addition to dependent resources, it is also important to consider the dependencies of the code itself, such as any required libraries or packages. These can be included as part of the deployment package for the function or managed through a package manager like npm or pip.

So how does it all come together?

Let’s say you have a serverless function that is responsible for processing and storing data in a database, which is triggered by an incoming message on an SQS queue and performs some computation on the data before storing it in a database.

In this example, the SQS queue and the database would be considered dependent resources of the serverless function. The serverless function would be configured to read messages from the SQS queue, and be given the necessary credentials and connection information to connect to the database.

Queue:
Type: AWS::SQS::Queue
Properties:
QueueName: My_Queue

The SQS queue and the database would be provisioned and managed separately from the serverless function, for example, you could use the AWS SQS service to create the queue and AWS RDS for the database.

my_table:
Type: AWS::DynamoDB::Table
Properties:
TableName: my_table
AttributeDefinitions:
- AttributeName: attribute1
AttributeType: S
KeySchema:
- AttributeName: attribute1
KeyType: HASH
BillingMode: PAY_PER_REQUEST

When the function is triggered by a new message on the queue, it would read the message, perform the computation, and write the results to the database. It’s important to note that dependent resources should be properly configured and scaled, so that the function can access the resources it needs and perform its intended task.

resources:
Resources:
usersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: my_table
AttributeDefinitions:
- AttributeName: attribute1
AttributeType: S
KeySchema:
- AttributeName: attribute1
KeyType: HASH
BillingMode: PAY_PER_REQUEST
Queue:
Type: AWS::SQS::Queue
Properties:
QueueName: My_Queue
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: My_Bucket

So to sum things up, dependent resources — such as databases and message queues — are required for a serverless function to perform its task. They need to be properly configured, scaled and monitored by the developer. In addition, dependencies of the code also need to be considered. Properly configuring dependent resources is crucial for the function to be able to access and perform its intended task.

But what do you think is there a reason why to use just Serverless or use hard coded elements that come from Terraform dynamically?

--

--

Tom Brovender
Develeap

DevOps Enginner @ Develeap | CKA | GitOps | TF Associate