skip to Main Content

The way that most databases typically work is through a consistent connection (mysql/postgres) etc, through a connection string to hit a server.

I am working with Lambda/DynamoDB and to my understanding, Dynamo is serverless, there is no consistent connection, it’s just http calls. I can’t see anywhere where I point the lambda at the dynamo table (other than in the IAM policy, giving it access to said table). Does it infer it from the IAM policy, or do I need to point this elsewhere?

3

Answers


  1. DynamoDB Table name is provided as an input when you make a request. That’s how Lambda knows which DynamoDB to connect to.

    Most people use the AWS SDK to connect to the DynamoDB. Table name is an input in the client.

    If you want to connect making HTTP calls, you’d be using the Low-level API. You still provide the Table name in the request. You can see the documentation here for that.

    Login or Signup to reply.
  2. You would typically pass the table name to the Lambda as an Environment Variable*. The table name is used in the DynamoDB SDK client to perform operations on the table.


    * You could also retrieve the table name value at runtime from the Systems Manager Parameter Store. But because table name is a fixed value, the environment variable approach is better.

    Login or Signup to reply.
  3. You’re partly correct in that it infers the account number and permissions needed from the IAM policy attached to your Lambdas ExecutionRole.

    And you’re also correct that DynamoDB is a http/https based connection, which uses short lived connections rather that the long lived ones that you may be more familiar with.

    Ultimately it comes down to how you configure your DynamoDB Client. It’s through the parameters you pass to your SDKs client that Lambda knows how to connect to that table. 2 important parameters here are the region_name and table_name:

    session = boto3.session.Session(region_name="eu-west-1")
    client = session.client('dynamodb')
    
    response = client.scan(
                TableName=table_name
                )
    
    

    Above you can see an example of a Scan in python, where you see the region being set and also the table name being passed as a parameter to the Scan function.

    Most people tend to store their table names as Lambda Environment Variables which allow you to set the tables name at creation time through infrastructure as code for example.

    https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStartedDynamoDB.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search