
The cost of running Lambda for your workload is determined by three factors: the number of executions, the duration and memory usage (combined as gigabyte-seconds), and data transfer. Beyond the impact of memory allocation discussed in the previous section, there are other design choices that impact these three variables and therefore can reduce cost.
Your choice of runtime can impact the cost. Generally, compiled languages run code more quickly than interpreted languages but can take longer to initialize. For small functions with simple functionality, often an interpreted language is better suited for the fastest total execution time, and therefore the lowest cost. Functions using compiled languages are often faster in workloads with heavier computational complexity or where you are using Provisioned Concurrency, so the initialization overhead occurs before the invocation.
Invocation frequency is a major factor in determining cost. Depending upon which events are triggering Lambda functions, there are various controls you can use to lower the total number of invocations. For Lambda functions triggered by:

From https://github.com/aws-samples/s3-to-lambda-patterns/blob/master/ddbImporter/v2/template.yaml
Also, consider the overall data transfer costs for your workload. Data transfer costs for Lambda are charged at the EC2 data transfer rates listed at https://aws.amazon.com/ec2/pricing/on-demand/ in the Data transfer section. Data transferred in from the internet is not subject to any transfer costs. Generally, you can minimize these costs by limiting how much data is passed in messages between microservices.
For more cost optimization information, see the Cost Optimization for AWS Lambda guide.