[英]Getting error while accessing AWS DynamoDB from AWS Lambda
我在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”是否存在
從這個文檔:
ResourceNotFoundException
消息:找不到請求的資源。
示例:正在請求的表不存在,或者處於CREATING狀態為時過早。
使用list-tables命令檢查該表是否存在:
aws dynamodb list-tables
驗證您的CLI默認區域是否與表的區域相同
如果該表確實存在,請檢查您的cli配置,以驗證您要查詢的表所在的區域是否相同。 您可以像這樣檢查默認區域:
aws configure get region
您可以使用aws configure
更改默認設置,或直接在任何CLI命令上指定--region
來覆蓋默認區域。
由於表不存在,我通常會收到該錯誤。
校驗:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.