Movatterモバイル変換


[0]ホーム

URL:


Upgrade to Pro — share decks privately, control downloads, hide ads and more …
Speaker DeckSpeaker Deck
Speaker Deck

Production-ready Lambda functions with Lambda P...

Avatar for Jeroen Reijn Jeroen Reijn
July 18, 2025

Production-ready Lambda functions with Lambda PowerTools

AWS Lambda is a great service that allows you to focus on delivering business value without worrying too much about the underlying infrastructure. It integrates well with all kinds of other AWS services, and Lambda functions can be written in many different languages.

To make your functions production-ready and to achieve operational excellence you'll need to apply the three pillars of observability: logs, metrics, and traces. The Powertools for AWS Lambda toolkit can help you with that, but there is so much more it can do to boost your productivity.

In this talk, we will explore the capabilities of Lambda Powertools and demonstrate how it can improve your lambda functions by looking at code examples, and a live demo of a production application.

Avatar for Jeroen Reijn

Jeroen Reijn

July 18, 2025
Tweet

More Decks by Jeroen Reijn

See All by Jeroen Reijn

Other Decks in Programming

See All in Programming

Featured

See All Featured

Transcript

  1. Production ready Lambda functions With Lambda PowerTools Jeroen Reijn

  2. Cloud Watch alarm

  3. None
  4. None
  5. Quick introduction Jeroen Reijn Cloud Solutions Architect[email protected] www.luminis.eu

  6. Case study

  7. X / Twitter Bot architecture

  8. Lambda Powertools Available for: - Python - Typescript / Javascript

    - Java - dotNet https://powertools.aws.dev
  9. Lambda Powertools – Key features Logger Metrics Tracer + Many

    more A developer toolkit to implement Serverless best practices and increase developer velocity
  10. Lambda Powertools – Key features Core Utilities • Tracing •

    Logging • Metrics Utilities * • Idempotency • Parameters • Larges messages • Batch processing • Validation • Custom Resources • Serialization Utils * Depends on language implementation
  11. Tracing AWS X-Ray

  12. Powertools Tracing – Key Features • Capture cold start as

    annotation, and responses as well as full exceptions as metadata • Helper methods to improve the developer experience of creating new X-Ray subsegments. • Better developer experience when developing with multiple threads. • Auto patch supported modules by AWS X-Ray
  13. View traces AWS X-Ray

  14. Trace segments

  15. View traces AWS X-Ray

  16. Trace segments - annotations

  17. Trace segments - metadata

  18. Global configuration

  19. Add custom tracing

  20. Instrumenting SDK & HTTP clients

  21. Instrumenting SDK clients

  22. Logger Amazon CloudWatch

  23. Powertools Logger – Key Features • Capture key fields from

    Lambda context, cold start and structures logging output as JSON • Log Lambda event when instructed, disabled by default, can be enabled explicitly via annotation param • Append additional keys to structured log at any point in time
  24. Global configuration

  25. Structured logging Key Type Example coldStart Boolean true service String

    “payment” functionName String "example-powertools- HelloWorldFunction- 1P1Z6B39FLU73" xray_trace_id String "1-5759e988- bd862e3fe1be46a994272793" …
  26. Enabling Logger

  27. Example structured log

  28. Example structured log

  29. Metrics Amazon CloudWatch

  30. Powertools Metrics – Key Features • Aggregate up to 100

    metrics using a single CloudWatch EMF object (large JSON blob). • Validate against common metric definitions mistakes (metric unit, values, max dimensions, max metrics, etc). • Metrics are created asynchronously by the CloudWatch service, no custom stacks needed. • Context manager to create a one off metric with a different dimension. Amazon CloudWatch
  31. What is CloudWatch EMF? “The CloudWatch embedded metric format is

    a JSON specification used to instruct CloudWatch Logs to automatically extract metric values embedded in structured log events. You can use CloudWatch to graph and create alarms on the extracted metric values.”
  32. Terminology • Namespace: Group of multiple metrics from multiple services

    for a given application • Dimensions: Metrics metadata in key value format. Helps you slice and dice, for example ColdStart or Service.
  33. Global configuration

  34. Enabling metrics

  35. Creating Metrics

  36. Creating Metrics

  37. Creating Metrics

  38. Creating Metrics • Create separate EMF blog only containing ColdStart

    metric • Add FunctionName and Service dimensions
  39. Batch processing AWS Lambda

  40. Lambda Event Source Mapping

  41. Background – Batch failures Succesful response Maximum retries Records expire

    Amazon Kinesis Amazon SQS Amazon DynamoDB Streams
  42. Batch processor – Key features • Reports batch item failures

    to reduce number of retries for a record upon errors • Simple interface to process each batch record • Integrates with Java Events library and the deserialization module • Build your own batch processor by extending primitives Amazon Kinesis Amazon SQS Amazon DynamoDB Streams
  43. None
  44. Handling Batches in SQS

  45. Handling Batches in SQS

  46. Handling Batches in SQS

  47. Handling Batches in SQS

  48. Idempotency

  49. What is idempotency? “The property of idempotency means that an

    operation does not cause additional side effects if it is called more than once with the same input parameters.” https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/
  50. Idempotency – Key features • Prevent Lambda handler function from

    executing more than once on the same event payload during a time window • Ensure Lambda handler returns the same result when called with the same payload • Select a subset of the event as the idempotency key using JMESPath expressions • Set a time window in which records with the same payload should be considered duplicates Amazon DynamoDB
  51. Example https://www.ranthebuilder.cloud/post/serverless-api-idempotency-with-aws-lambda-powertools-and-cdk

  52. Example – First attempt https://www.ranthebuilder.cloud/post/serverless-api-idempotency-with-aws-lambda-powertools-and-cdk Creates hash for the request

    payload
  53. Example – Networking connection dropped https://www.ranthebuilder.cloud/post/serverless-api-idempotency-with-aws-lambda-powertools-and-cdk Checks hash for the

    request payload
  54. Idempotency Table

  55. Idempotency Table

  56. Idempotency Table

  57. Parameters

  58. Parameters – Key features • Retrieve one or multiple parameters

    from the underlying provider • Cache parameter values for a given amount of time (defaults to 5 seconds) • Transform parameter values from JSON or base 64 encoded strings Amazon DynamoDB AWS Systems Manager – Parameter store AWS AppConfig AWS Secrets Manager
  59. Annotation style parameter injection

  60. Parameters provider

  61. Parameters provider

  62. Parameters provider

  63. Parameters provider

  64. Large messages

  65. Large Messages – Key features • Automatically retrieve the content

    of S3 objects when SQS or SNS messages have been offloaded to S3. • Automatically delete the S3 Objects after processing succeeds. • Compatible with the batch module (with SQS).
  66. Putting Large Messages in S3 • Amazon SQS Extended Client

    Library for Java • Amazon SQS Extended Client Library for Python Send large messages, especially for payloads between 256 KB and 2 GB.
  67. Using large messages from S3 for SQS

  68. X / Twitter Bot architecture - PowerTooled Batch Parameters AWS

    X-Ray Amazon CloudWatch Metrics Logger Batch Tracer
  69. Key takeaways Lambda Powertools: • Helps you implement cross cutting

    concernts in minutes • Is available for most lambda runtimes • Makes batch processing easy • Helps mitigate idempotency issues • Brings a lot more tools which makes your lambda functions better

[8]ページ先頭

©2009-2025 Movatter.jp