How to access DynamoDB from AWS Lambda when using the Serverless Framework?

I'm using the Serverless Framework to manage my AWS Lambda deploys. The framework credentials has access to DynamoDB resources, but my Lambda, deployed with the framework, can't access my DynamoDB tables.

How can I give my Lambda functions the proper access?

Answers 1

  • EDIT: updated the answer for Serverless Framework 1.x.

    The solution is to set the iamRoleStatements to allow Lambda to access the DynamoDB resources. Note: the credentials used by the Serverless Framework must have permission to the same DynamoDB resources.

    1. add the iamRoleStatements in your serverless.yml:

        name: aws
        runtime: nodejs4.3
        stage: dev
        region: us-east-1
          - Effect: "Allow"
              - "dynamodb:*"
            Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/*"
    2. deploy the changes:

      > serverless deploy

    To give permissions in a function level (instead of allowing all functions to access DynamoDB), see my other answer here.

Related Articles