Reputation: 109
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'
}
)
ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the GetItem operation: Requested resource not found
Upvotes: 1
Views: 2302
Reputation: 2943
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.
Upvotes: 3
Reputation: 208
I have gotten that error often usually due to the table not existing.
Check:
Upvotes: 0