dynobase-icon
Dynobase

DynamoDB permissions for Lambda: policies and setup

Charlie Fish

Written by Charlie Fish

Last updated: October 23rd, 2026

Switching between AWS accounts and roles? Dynobase connects through your existing AWS profiles, SSO sign-in and assumed roles. AWS sign-in in Dynobase

Give a Lambda function DynamoDB access by granting the required actions on the required resources to its execution role. A function that reads one item needs dynamodb:GetItem on that table; querying an index requires access to the index ARN too. Lambda supplies temporary credentials to the AWS SDK, so you do not need access keys in the function code or environment variables.

Understand the role, trust policy and permissions policy

IAM authenticates and authorizes AWS API requests. An IAM role is an identity with temporary credentials and a trust policy that identifies who can assume it. Permissions policies specify what that identity can do after assumption. Lambda uses one execution role, which can have multiple permissions policies.

For a Lambda execution role, the trust policy allows the Lambda service to assume it:

That statement does not grant DynamoDB access. Add a separate permissions policy for the operations the handler performs. Similarly, permission to invoke a Lambda function does not grant the function permission to call DynamoDB.

Start with a table-scoped IAM policy

This policy preserves a simple read-only use case: MyApp_Production_Users has a string partition key named id, and the function reads one user by that key.

Replace the Region, account ID and table name. The policy allows reading any item in this table, but it grants no writes, scans, table deletion or access to other tables. Add a partition-key condition if access must be narrower.

Which DynamoDB IAM actions do you need?

Application operationIAM actionResource
Read one item by primary keydynamodb:GetItemTable ARN
Read multiple named itemsdynamodb:BatchGetItemEvery table referenced
Query a tabledynamodb:QueryTable ARN
Query an indexdynamodb:QueryIndex ARN, with appropriate table permissions
Create or replace an itemdynamodb:PutItemTable ARN
Update selected attributesdynamodb:UpdateItemTable ARN
Delete an itemdynamodb:DeleteItemTable ARN
Batch puts or deletesdynamodb:BatchWriteItemEvery table referenced
Read table configurationdynamodb:DescribeTableTable ARN

Do not add Scan just because a tutorial lists it. Conversely, a tool that really scans a table needs dynamodb:Scan; GetItem does not cover that operation. PartiQL uses its own action permissions, so an SDK GetCommand and a PartiQL SELECT are not interchangeable authorization tests.

If the function queries a ByEmail index, grant Query explicitly:

This is an additional statement, not a requirement for the GetItem handler below. See DynamoDB access control for conditions and resource-policy examples.

Attach the policy in the AWS console

  1. Open IAM Policies, create a policy and paste the table-scoped JSON into the JSON editor. Review the resource ARN and give the policy a descriptive name.
  2. Open IAM Roles and create a role with Lambda as its trusted service, or use the function's existing execution role.
  3. Attach the DynamoDB policy and the logging permissions the function needs. Replacing an existing role without preserving logging permissions can make diagnosis harder.
  4. Open the Lambda function's Configuration, then Permissions. Edit the execution role selection and choose the role you configured.
  5. Invoke the function with a known key and confirm both a successful read and a denied operation outside the intended scope.

The following screenshots illustrate the older console workflow; labels and layout may differ in your account. The role and policy relationship is unchanged.

Older IAM create-role wizard with Lambda selected as the trusted service

Older IAM wizard attaching a DynamoDB permissions policy to the execution role

Older Lambda permissions panel showing the current execution role

Older Lambda role editor selecting an existing IAM execution role

The deploying identity needs permission to assign the role, including the applicable iam:PassRole permission. These deployment permissions belong to the deployer, not automatically to the function's runtime role.

Terraform example with a supported Lambda runtime

This example creates the table, role, read policy and function. It uses nodejs24.x and assumes you have packaged index.mjs and its dependencies into assets/function.zip. The GetItem operation needs no secondary index.

The managed basic execution policy supplies logging permissions. For a tightly controlled deployment, replace it with a policy scoped to a pre-created log group. Set the AWS provider to the Region where the application should run.

Read with AWS SDK for JavaScript v3

Bundle @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb with your function. Save this handler as index.mjs:

This is a service-level example. If an API caller supplies id, authenticate that caller and authorize access to that user's record before reading. IAM sees the Lambda role, not the human behind each request.

Restrict items with dynamodb:LeadingKeys

To restrict the example role to a specific partition key, add this condition to its GetItem statement:

LeadingKeys means partition-key values, not attribute names or sort keys. Use only actions that support the condition. A shared execution role does not automatically receive a different IAM condition for each HTTP request, so this static example is suitable for a dedicated workload, not a complete multitenant API design. AWS documents the available fine-grained condition keys.

Streams triggers need stream permissions

A function that consumes DynamoDB Streams needs a different permission set from a function that calls GetItem. Its execution role needs DescribeStream, GetRecords, GetShardIterator and ListStreams. Grant the first three on the intended stream ARN; allow discovery separately where needed:

Add CloudWatch Logs permissions as well. AWSLambdaDynamoDBExecutionRole is the AWS managed starting point, but a custom policy can scope stream reads more narrowly. An event source mapping polls the stream and invokes the function; granting lambda:InvokeFunction to DynamoDB alone does not set it up. Follow the Lambda event source mapping procedure.

Resource-based policies and cross-account access

A table can grant access to a Lambda execution role in another account through its resource-based policy. The role also needs an identity policy allowing the same action on the table ARN. Use that full ARN as TableName; a bare name identifies a table in the caller's account.

Cross-account Streams event source mappings are supported too. Grant the execution role access in the stream's resource policy as well as in its own identity policy, and configure the mapping in the function's account. The function and stream must use the supported same-Region setup. Review AWS's cross-account examples, including encryption prerequisites: tables encrypted with the AWS managed key do not support resource-policy cross-account access.

Broad policies, prefixes and troubleshooting

A resource ending in table/MyPrefix* grants access to every matching table, including ones created later. Use that pattern only when the naming convention is an intentional authorization boundary. An action wildcard such as dynamodb:* also grants administrative operations and should not be a shortcut for a failing read.

The old AmazonDynamoDBFullAccess managed policy is deprecated. Its replacement, AmazonDynamoDBFullAccess_v2, is narrower in related-service permissions but still grants full DynamoDB access. It is an administrative policy, not a least-privilege Lambda policy.

For AccessDeniedException, inspect the denied action, resource and assumed-role identity. Check the deployed role, table and index ARNs, explicit denies, permission boundaries, organization policies, endpoint policy and KMS access. A timeout instead suggests a network path problem; a VPC-connected Lambda may need a VPC endpoint or another valid route. Test with the function's credentials, not an administrator's CLI profile.

Frequently Asked Questions

Why does Lambda need DynamoDB permissions?

The execution role must be authorized for each DynamoDB action and resource the handler uses. A basic Lambda logging role does not grant table access.

Can I give Lambda full DynamoDB access?

Yes, but an application usually needs a much smaller policy. AmazonDynamoDBFullAccess_v2 is the current full-access managed policy; scope production function permissions to the required actions and resources.

Can a Lambda function have multiple execution roles?

A function has one execution role. You can attach multiple permissions policies to it, and application code can assume another role when explicitly authorized.

What is the difference between a role and a policy?

A role is an IAM identity that can be assumed to obtain temporary credentials. A policy is a document defining permissions or, for a trust policy, who can assume the role.

Do I need AWS access keys in my Lambda function?

No. Lambda supplies temporary execution-role credentials, and the AWS SDK uses them automatically.

Does GetItem permission let Lambda read a DynamoDB stream?

No. Streams use separate read actions on a stream ARN, and Lambda needs an event source mapping to poll and deliver those records.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase