1

I am getting the error for following boto3 code in lambda to access dynamo db table through STS credentials. The code is below

import boto3
def lambda_handler(event, context):
sts_client = boto3.client('sts')

# Call the assume_role method of the STSConnection object and pass the role
# ARN and a role session name.
assumedRoleObject = sts_client.assume_role(
    RoleArn="arn:aws:iam::012345678910:role/test_role",
    RoleSessionName="AssumeRoleSession1"
)

# From the response that contains the assumed role, get the temporary
# credentials that can be used to make subsequent API calls
credentials = assumedRoleObject['Credentials'] 


dynamoDB = boto3.resource('dynamodb',aws_access_key_id=credentials['AccessKeyId'],aws_secret_access_key=credentials['SecretAccessKey'],aws_session_token=credentials['SessionToken'],)
test1=dynamoDB.get_available_subresources

table = dynamoDB.Table('Test1')

response = table.get_item(
    Key={
            'Name': 'ABC'
        }
    )

The error stacktrace is below:

ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the GetItem operation: Requested resource not found
4
  • 1
    you didn't include the stack trace, only the error Commented Mar 22, 2018 at 14:11
  • 2
    Does the table exist? If so, shouldn't you define region_name in your dynamoDB resource object? Commented Mar 22, 2018 at 15:33
  • Getting same error even after adding region_name Commented Mar 23, 2018 at 5:15
  • Just saying, table names are case sensitive Commented Mar 23, 2018 at 7:58

2 Answers 2

3

First check whether Table "Test1" exists

From this documentation:

ResourceNotFoundException

Message: Requested resource not found.

Example: Table which is being requested does not exist, or is too early in the CREATING state.

Check whether this table exists with the list-tables command:

aws dynamodb list-tables

Verify whether your CLI default region is the same as your table's region

If this table does exist, check your cli configuration to verify that you're querying in the same region that the table exists. You can check your default region like this:

aws configure get region

You can use aws configure to change your default settings, or specify --region directly on any CLI command to override your default region.

Sign up to request clarification or add additional context in comments.

Comments

0

I have gotten that error often usually due to the table not existing.

Check:

  1. Table exists and spelling is correct
  2. You are accessing the right DynamoDB instance where your table exists
  3. The role you are using has access to the table

1 Comment

Yes,table exists and the role has administrator access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.