【发布时间】:2018-03-23 15:37:16
【问题描述】:
我在 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
【问题讨论】:
-
你没有包括堆栈跟踪,只有错误
-
该表是否存在?如果是这样,您不应该在您的 dynamoDB 资源对象中定义
region_name吗? -
即使添加了 region_name 也出现同样的错误
-
只是说,表名区分大小写
标签: python amazon-web-services aws-lambda amazon-dynamodb boto3