在 Lambda 函数中调用 DynamoDB 时,如何在 Amplify 中引用 GraphQL 模型使用的 table 的名称?
How to reference the name of the table used by GraphQL models in Amplify when calling a DynamoDB in Lambda function?
我正在尝试使用 AWS Amplify 设置 GraphQL api。文档提供了从 Python:
中的 Lambda 函数调用 DynamoDB 的解决方案
import json
import boto3
client = boto3.client('dynamodb')
def handler(event, context):
data = client.scan(
TableName='your-table-name'
)
response = {
'statusCode': 200,
'body': json.dumps(data),
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
}
return response
我想不通的是如何引用 GraphQL 模型在 Amplify 中使用的 table 的名称以将其放入 TableName='your-table-name'
(这样它既适用于云版本又适用于嘲笑)。有什么想法吗?
编辑:通过将函数更新为 read/edit table 的权限来解决。然后可以使用环境变量引用 table。
我想我明白了你的问题,但在这里尝试引用 table 听起来不是最好的选择。
看看来自 AWS 的 post,它展示了如何通过 amplify mock api
在本地运行放大
https://aws.amazon.com/pt/blogs/mobile/amplify-framework-local-mocking/
我通过将函数更新为 read/edit table 的权限解决了这个问题。然后可以使用环境变量引用 table。
我正在尝试使用 AWS Amplify 设置 GraphQL api。文档提供了从 Python:
中的 Lambda 函数调用 DynamoDB 的解决方案import json
import boto3
client = boto3.client('dynamodb')
def handler(event, context):
data = client.scan(
TableName='your-table-name'
)
response = {
'statusCode': 200,
'body': json.dumps(data),
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
}
return response
我想不通的是如何引用 GraphQL 模型在 Amplify 中使用的 table 的名称以将其放入 TableName='your-table-name'
(这样它既适用于云版本又适用于嘲笑)。有什么想法吗?
编辑:通过将函数更新为 read/edit table 的权限来解决。然后可以使用环境变量引用 table。
我想我明白了你的问题,但在这里尝试引用 table 听起来不是最好的选择。
看看来自 AWS 的 post,它展示了如何通过 amplify mock api
在本地运行放大
https://aws.amazon.com/pt/blogs/mobile/amplify-framework-local-mocking/
我通过将函数更新为 read/edit table 的权限解决了这个问题。然后可以使用环境变量引用 table。