Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Recommendations and best practices

Pragya Keshap answered on February 20, 2023 Popularity 2/10 Helpfulness 1/10

Contents


More Related Answers

  • Best Practices
  • Best Practices#
  • Follow best practices

  • Recommendations and best practices

    0

    Optimize your code: Writing syntactically correct Lambda functions is one thing and writing optimized functions is totally another. For example, it's always a good practice to initialize any external services like DynamoDB, SNS outside your function code. The reason for this is simple, each time Lambda starts your code, the underlying container starts up. At this point, the code outside the handler runs first (initialization). When subsequent function calls are invoked, Lambda reuses the same container to run your functions and as a result you save resources and time by not instantiating the external services again.

    Versioning and aliases: As discussed before, versioning and aliases are a very important set of tools that you should leverage when creating and promoting Lambda functions from one environment to another. As a best practice, you should look at tools such as Claudia.js or APEX that help you automate versioning and thus reduce on errors during deployments.

    Environment variables: Leverage environment variables to create reusable Lambda functions. Additionally, you can also encrypt the environment variables for an added layer of security for your functions using either your own keys or the KMS service.

    Security: So far we haven't launched any of our Lambda functions in our own VPCs and have opted to use the defacto VPC that AWS uses to host the functions, however, in production environments it is highly advised you launch your functions in your own VPCs.

    Incorrect/missing IAM permissions: Always make sure you follow the least privileges approach when creating and assigning IAM permissions and roles to your functions. Also as a best practice, enable AWS CloudTrail on your prod accounts to audit your Lambda functions and look for any unauthorized calls to sensitive AWS resources.

    Allocating correct amount of resources: Remember that Lambda pricing varies based on the timeout as well as the amount of RAM that you provide to your functions. You should also note that the memory that you provide to your functions also impact the overall function performance; including CPU and network as well. So more the memory, the higher the cost as well.

    Monitoring functions: Although Lambda functions are designed around the concept of fire and forget, it is very important that you monitor your function's execution at all times using either third-party tools, services, or even with CloudWatch Logs. Monitoring your functions helps you to effectively optimize your code as well as strategize your function's resource requirements which have a direct impact on the costs of overall executions.

    Popularity 2/10 Helpfulness 1/10 Language whatever
    Source: Grepper
    Tags: whatever
    Link to this answer
    Share Copy Link
    Contributed on Feb 20 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.