I have a very simple webservice in AWS Lambda using Python and Flask (Service A). The service receive a request and perform a DynamoDB query and returns the results. DynamoDB has on-demand capacity and almost in all cases return 1 result.
I perform the query with the following function.
class DynamoDB:
def __init__( self ):
session = boto3.Session( )
self.dynamodb = session.resource( 'dynamodb' )
def query( self, table_name, **kwargs ):
# Selected Table
table = self.dynamodb.Table( table_name )
# Request to table
response = table.query( **kwargs )
return response
Query Expression
"#user_id = :user_id and begins_with( #sort_key, :sort_key)"
Response size ~ 400B
I encounter some issues with the performance such as for a single request take 1040ms with AWS Lambda Memory to 128MB and Max Memory Used to 95-100 MB. All the time except of 4ms consumed in the DynamoDB query.
Below are the response times when I increase the memory.
128 MB -> 1040 ms
512 MB -> 520 ms
1024 MB -> 210 ms
Now I have an another webservice in AWS Lambda (Service B) which is using Python, Flask, Pandas and PyODBC. The service receive a request and perform 2 simple queries to MSSQL server which is not hosted in AWS and return the results. This service has 128MB of Memory and Max Memory Used: 128 MB (consume all the memory). The performance for a single request to this service is 500ms.
Can someone explain me how is that possible ?
Is there any solution in order to make the query in Service A faster ?