我在lambda中跟踪boto3代码以通过STS凭据访问Dynamo db表时出错。代码如下
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
首先检查表“Test1”是否存在
从这个留档:
资源未找到异常
消息:未找到请求的资源。
示例:正在请求的表不存在,或者处于CREATING状态太早。
使用list-table命令检查此表是否存在:
aws dynamodb list-tables
验证CLI默认区域是否与表的区域相同
如果此表确实存在,请检查您的cli配置以验证您是否在该表存在的同一区域中进行查询。您可以像这样检查您的默认区域:
aws configure get region
您可以使用aws confiure
来更改默认设置,或者直接在任何CLI命令上指定--region
来覆盖您的默认区域。
我经常得到这个错误,通常是由于表不存在。
检查: