我正在尝试调用 Lambda 的突变,该突变由计时器定期触发。这就是我正在做的
const params = {
AccountId: "XXXXXXX",
RoleArn: "arn:aws:iam::XXXX:role/appsync_lamda_role", // tried removing this too
IdentityPoolId: "ap-southeast-1:xxxx-xxxx-xxx-xxxx-xxx",
LoginId: "demo_access" // tried with and without this
};
AWS.config.update({
region: "ap-southeast-1",
credentials: new AWS.CognitoIdentityCredentials(params)
});
Run Code Online (Sandbox Code Playgroud)
现在,我打电话
AWS.config.credentials.get(err => {
const signer = new AWS.Signers.V4(httpRequest, "appsync", true);
signer.addAuthorization(AWS.config.credentials, AWS.util.date.getDate());
const options = {
method: httpRequest.method,
body: httpRequest.body,
headers: httpRequest.headers
};
fetch(uri.href, options)
.then(res => res.json())
.then(json => {
console.log(`JSON Response = ${JSON.stringify(json, null, 2)}`);
callback(null, event);
})
.catch(err => {
console.error(`FETCH ERROR: …Run Code Online (Sandbox Code Playgroud) 我的模拟不会为每个项目生成唯一的数据,而是每个项目都具有相同的字段值。
选项1:(理想的方法,错误的结果)
AppSync 架构包含一个items字段[Model],如果我将Model解析器单独放置,则列表Model中的所有值都items具有相同的值。
const mocks = {
ModelModelConnection: () => ({
items: () => new MockList(5),
}),
Model: () => ({
id: casual.uuid,
name: casual.title,
}),
};
Run Code Online (Sandbox Code Playgroud)
结果是...

选项2:(替代方法,正确结果)
const mocks = {
ModelModelConnection: () => ({
items: () => new MockList(5, () => ({
id: casual.uuid,
name: casual.title,
})),
}),
};
Run Code Online (Sandbox Code Playgroud)

我想选择选项 1,但我似乎无法让独特的项目被嘲笑。我一直在为这个摸不着头脑。提前致谢!
我正在使用 BatchGetItem 从 dynamodb 获取多个项目。但我需要根据某些条件过滤项目。
例如:我有一个具有 id 和状态的任务表。我需要获取 id 1、2、3 的项目,其中 status=done。
#set($ids = [1,2,3])
{
"operation" : "BatchGetItem",
"tables" : {
"userTable": {
"keys": $util.toJson($ids)
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 graphql 查询示例,我想将其进一步绑定到 React-Native 应用程序中的 FlatList 对象。但我仍然在努力理解我应该传递 nextToken 参数,以便获得发往第二页的对象切片......
尝试传递下一个或最后一个 id 或索引,但它不起作用 - 它要求我提供有效的 nextToken,我不知道它是什么类型的数据。
我正在通过 AppSynch 控制台运行。
我的查询:
query ListResources(
$nextTokenPlants: String = "Orange Tree"
$limitPlants: Int = 3
) {
listResources {
items {
id
name
Plants(limit: $limitPlants, nextToken:$nextTokenPlants) {
items {
id
name
filterName
description
bath
tea
insence
children
}
nextToken
}
}
nextToken
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的结果:
{
"data": {
"listResources": {
"items": [
{
"id": "361dee16-d567-41ed-b1d4-9baa4a7ffdcc",
"name": "Plantas",
"Plants": null
}
],
"nextToken": null
}
}, …Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用 React Native。在我的旧机器上,当我运行 amplify status 时,我列出了Auth和Api服务Storage。
我搬到我的新机器,安装了节点、watchman、brew 等...然后导航到我的 React Native 项目并运行:react-native run-ios,瞧,我的应用程序正在运行。对我的 AWS Api、Auth 和 Storage 的所有调用都运行良好。
现在我可以发出一些放大命令。例如amplify status。我试过:amplify env add这就是我得到的:
Users-MBP-2:projectname username$ amplify env add\nNote: It is recommended to run this command from the root of your app directory\n? Do you want to use an existing environment? Yes\n? Choose the environment you would like to use: dev\nUsing default provider awscloudformation\n\xe2\x9c\x96 There was an error …Run Code Online (Sandbox Code Playgroud) 我希望能够在考虑限制之前使用查询操作过滤分页结果。是否有任何建议可以在过滤后的结果上获得正确的分页?
我想使用以下逻辑实现 DynamoDB 扫描或查询:
Scanning -> Filtering(boolean true or false) -> Limiting(for pagination)
Run Code Online (Sandbox Code Playgroud)
但是,我只能使用以下逻辑实现扫描或查询:
Scanning -> Limiting(for pagination) -> Filtering(boolean true or false)
Run Code Online (Sandbox Code Playgroud)
注意:我已经尝试过全局二级索引,但在我的情况下它不起作用,因为我有 5 个不同的属性要过滤和限制。
我想在 CloudFront 发行版后面部署 AppSync API。
CloudFront 发行版需要 HTTP 源,如何从一个 CDK 堆栈内的 API 对象获取此源?
因此,我创建了一个解析器来使用以下代码在表中创建一个项目。
const configSettingsDS = api.addDynamoDbDataSource('configSettingsDynamoTable', configurationSettingsTable);
configSettingsDS.createResolver({
typeName:'Mutation',
fieldName: 'createConfigSettings',
requestMappingTemplate: appsync.MappingTemplate.dynamoDbPutItem(
appsync.PrimaryKey.partition('id').auto(),
appsync.Values.projecting('configSettings')),
responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(),
});
Run Code Online (Sandbox Code Playgroud)
我似乎找不到一个可以在更新操作中复制相同内容的方法。任何帮助表示赞赏。谢谢
我正在使用 Postman 连接 AWS Appsync订阅: https: //docs.aws.amazon.com/appsync/latest/devguide/real-time-websocket-client.html
具有以下配置:
{“payload”:{“errors”:[{“message”:“NoProtocolError”,“errorCode”:400}]},“type”:“connection_error”}
我有 AWS AppSync API 和 DynamoDb,我可以使用DynamoDb Resolvers创建并从中获取数据。(VTL模板)
我不确定如何使用 VTL 模板进行用户输入验证。我想确保联系人的“firstName”长度在 2 - 30 个字符之间。
如何使用 VTL 实现这一目标?有没有办法在 GraphQL 模式本身内进行这种验证?
这是我的 GraphQL 架构,
schema {
query: Query
mutation: Mutation
}
type Mutation {
createContact(contact: ContactInput!): Contact!
}
type Contact {
contactId: ID!
firstName: String!
lastName: String!
email: String!
}
input ContactInput {
firstName: String!
lastName: String!
email: String!
}
Run Code Online (Sandbox Code Playgroud) aws-appsync ×10
graphql ×3
aws-cdk ×2
aws-amplify ×1
javascript ×1
lambda ×1
mocking ×1
resolver ×1
serverless ×1
typescript ×1
websocket ×1