Skip to content

Idempotency Getting Started Documentation #377

Closed
@weallwegot

Description

@weallwegot

What were you initially searching for in the docs?
I want to use the idempotency power tool utility to help prevent lambdas from multiple executions

Is this related to an existing part of the documentation? Please share a link
https://awslabs.github.io/aws-lambda-powertools-python/utilities/idempotency/

Describe how we could make it clearer
Currently there is a template.yml provided to set up the DynamoDB table required for the example, but it would be great to also have just screenshots of how one would set up DynamoDB from the console as well. I'm having an issue configuring my table correctly and i cant pinpoint if I've done it wrong or its an issue elsewhere.

Could also be helpful to note if anything needs to be done differently if you are setting up with a lambda that exists in a VPC, for instance do i need an endpoint?

If you have a proposed update, please share it here

Proposed update would be another tab next to the template.yml that shows the equivalent configuration for the console.

Activity

michaelbrewer

michaelbrewer commented on Mar 31, 2021

@michaelbrewer
Contributor

@cakepietoast @heitorlessa hopefully a good case for an article / repo for idempotent feature.

michaelbrewer

michaelbrewer commented on Mar 31, 2021

@michaelbrewer
Contributor

@weallwegot here is an example using CDK to provision the table. I can put up a full Gist for this

from aws_cdk import core as cdk, aws_lambda, aws_dynamodb
from aws_cdk.aws_lambda_python import PythonFunction


class CdkStack(cdk.Stack):
    def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        table = aws_dynamodb.Table(
            scope=self,
            id="idemTable",
            table_name="idem-dev",
            partition_key=aws_dynamodb.Attribute(name="id", type=aws_dynamodb.AttributeType.STRING),
            time_to_live_attribute="expiration",
            billing_mode=aws_dynamodb.BillingMode.PAY_PER_REQUEST,
        )

        func = PythonFunction(
            scope=self,
            id="idemFunction",
            entry="idem/",
            function_name="idem-dev",
            runtime=aws_lambda.Runtime.PYTHON_3_8,
            environment={"LOGGING": "DEBUG", "IDEM_TABLE": table.table_name},
        )
        table.grant_read_write_data(func)

The actual python lambda in idem/index.py:

import json
import os
import uuid

from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.idempotency import idempotent, DynamoDBPersistenceLayer, IdempotencyConfig

logger = Logger()

@idempotent(
    persistence_store=DynamoDBPersistenceLayer(table_name=os.environ["IDEM_TABLE"]),
    config=IdempotencyConfig(
        event_key_jmespath="headers.idempotentKey",
        raise_on_no_idempotency_key=True,
        use_local_cache=True,
    ),
)
def handler(event, context):
    logger.info(event)
    return {
        "statusCode": 200,
        "headers": {"Content-type": "application/json"},
        "body": json.dumps({"message": "Hello", "uuid": str(uuid.uuid4())}),
    }
self-assigned this
on Apr 9, 2021
heitorlessa

heitorlessa commented on Apr 9, 2021

@heitorlessa
Contributor

hey @weallwegot Thanks for helping us make the docs better!

I've added a table explaining the two configuration and their values that we expect if you're not overriding the default behaviour - Thanks to your suggestion, this should help anyone not using Infrastructure as Code to quickly create one in the Console.

I didn't add a Console screenshot as this might change and misguide customers, for example if the TTL attribute can be created in a different part of the console.

Docs: https://awslabs.github.io/aws-lambda-powertools-python/develop/utilities/idempotency/#required-resources

image

added this to the 1.14.0 milestone on Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

Status

Triage

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @heitorlessa@michaelbrewer@weallwegot

      Issue actions

        Idempotency Getting Started Documentation · Issue #377 · aws-powertools/powertools-lambda-python