标签: aws-appsync

AWS从后端放大console.log()

我已经使用“amplify add api”设置了无服务器快速功能(与API网关集成)。例如,如果我从其中一条路线记录一些内容:

app.get('/items', function (req, res) {console.log('hello')}

我在哪里可以找到你好?

aws-appsync aws-amplify

5
推荐指数
1
解决办法
1972
查看次数

如何使用 IAM 在 AWS Lambda 中调用 AppSync?

我目前正在使用 AppSync 在 AWS Lambda 中实施订阅突变。我想使用 IAM 并避免使用任何其他类型的 AUTH 机制,因为我在 AWS 堆栈中调用它。不幸的是,我收到以下 403 错误:

(摘自 SQS 的 CloudWatch 日志)

 {
    "errorMessage": "Response not successful: Received status code 403",
    "name": "ServerError",
    "errorType": "UnrecognizedClientException",
    "message": "The security token included in the request is invalid."
 }
Run Code Online (Sandbox Code Playgroud)

我尝试遵循这些但无济于事,但我不知道我错过了什么:

这是我当前调用它的代码:

import AWS from "aws-sdk";
import { AWSAppSyncClient } from "aws-appsync";
import { Mutation, mutations } from …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-lambda graphql aws-appsync

5
推荐指数
1
解决办法
3216
查看次数

如何处理需要在 AppSync/GraphQL 中连接来自多个数据源的数据的列表?

type Employee {
    id: String!
    name: String
    lastObservedStatus: String
}

type Query {
    employees: [Employee]
}
Run Code Online (Sandbox Code Playgroud)

这是一个虚构的模式来说明我的问题。我有两个单独的数据源,它们返回需要连接的列表才能填充响应。第一个数据源“员工列表 api”是一个 http API,我可以查询以获取权威的员工列表,我可以使用它来填充 和idname。例如,我收到这样的回复:

[
    {"id": "001", "name": "Harry"},
    {"id": "002", "name": "Jerry"},
    {"id": "003", "name": "Larry"}
]
Run Code Online (Sandbox Code Playgroud)

我有第二个 http API“员工观察日志”,我可以查询以获取状态列表以及关联的 ID。该 ID 允许我将号码与员工记录中的条目关联起来,并且我有一个记录日期。可能有不止一条状态记录,但在 GraphQL 中我只想选择最新的一条。响应示例:

[
    {"id":"002", "TimeStamp":"2021-07-01T12:30:00Z", "status": "eating"},
    {"id":"002", "TimeStamp":"2021-07-01T13:10:00Z", "status": "staring out the window"},
    {"id":"001", "TimeStamp":"2021-07-01T16:00:00Z", "status": "sleeping in lobby"}
]
Run Code Online (Sandbox Code Playgroud)

现在,我希望 graphQL 响应返回如下内容:

{
  "data": {
    "employees": [
      {
        "id": "001",
        "name": "Harry",
        "lastObservedStatus": …
Run Code Online (Sandbox Code Playgroud)

graphql aws-appsync aws-appsync-resolver

5
推荐指数
1
解决办法
928
查看次数

什么是正确的 AWSJSON?

我用过这个

var jsonData = {"hello": 20};
Run Code Online (Sandbox Code Playgroud)

将其传递给 graphql 查询时

products:jsonData
Run Code Online (Sandbox Code Playgroud)

它因此错误而失败

WrongType 类型的验证错误:值为 'StringValue{value='{hello: 20}'}' 的参数 'input.products' 不是有效的 'AWSJ

附:帮助

json dart flutter aws-appsync aws-amplify

5
推荐指数
1
解决办法
6492
查看次数

AppSync BatchResolver AssumeRole 错误

我正在尝试使用新的 DynamoDB BatchResolvers 写入 AppSync 解析器中的两个 DynamoDB 表(当前使用 Lambda 函数来执行此操作)。但是,在查看 CloudWatch 日志时,我收到以下权限错误:

“User: arn:aws:sts::111111111111:assumed-role/appsync-datasource-ddb-xxxxxx-TABLE-ONE/APPSYNC_ASSUME_ROLE is not authorized to perform: dynamodb:BatchWriteItem on resource: arn:aws:dynamodb:us-east-1:111111111111:table/TABLE-TWO (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: AccessDeniedException;

TABLE-ONE在解析器中用作数据源。

我添加了"dynamodb:BatchWriteItem""dynamodb:BatchGetItem"toTABLE-ONE的权限:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "dynamodb:BatchGetItem", "dynamodb:BatchWriteItem", "dynamodb:PutItem", "dynamodb:DeleteItem", "dynamodb:GetItem", "dynamodb:Scan", "dynamodb:Query", "dynamodb:UpdateItem" ], "Resource": [ "arn:aws:dynamodb:us-east-1:111111111111:table/TABLE-ONE", "arn:aws:dynamodb:us-east-1:111111111111:table/TABLE-ONE/*", "arn:aws:dynamodb:us-east-1:111111111111:table/TABLE-TWO", "arn:aws:dynamodb:us-east-1:111111111111:table/TABLE-TWO/*" ] } ] }

我有另一个使用该BatchGetItem操作的解析器,并在我的响应中获取空值 - 更改表的策略访问级别修复了空值: 在此处输入图片说明

但是,选中该框BatchWriteItem似乎并不能解决将权限添加到数据源表的策略的问题。 …

amazon-dynamodb amazon-iam aws-appsync

4
推荐指数
1
解决办法
1647
查看次数

AppSync 和 GraphQL 枚举突变

我在 AppSync for GraphQL 中有以下架构

input CreateTeamInput {
    name: String!
    sport: Sports!
    createdAt: String
}

enum Sports {
    baseball
    basketball
    cross_country
}
type Mutation{
    createTeam(input: CreateTeamInput!): Team
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试通过 AWS Amplify 库执行查询时

export const CreateTeam = `mutation CreateTeam($name: String!, $sport: String!){
  createTeam(input:{name:$name, sport:$sport}) {
    id,
    name,
    sport
  }
}
`;

....

API.graphql(graphqlOperation(CreateTeam, this.state))
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:Validation error of type VariableTypeMismatch: Variable type doesn't match

如何更新我的代码以使用此枚举类型?

amazon-web-services graphql aws-appsync aws-amplify

4
推荐指数
1
解决办法
3854
查看次数

附加项目以使用AWS AppSync列出DynamoDB

这可能是一个愚蠢的问题,但我确实找不到解决该问题的方法。

因此,我有DynamoDB表,并且在AppSync api中有架构。在表中,对于每一行,都有一个字段,其中包含一个列表作为其值。那么,如何在不替换现有项目的情况下将多个项目添加到此列表中呢?我应该如何编写该突变的解析器?

这是我的桌子的屏幕截图:

表图片

您会看到列表中有多个程序。

我怎样才能再追加两个程序。

这是我的解析器的新屏幕截图:解析器的 屏幕截图 我想在UpdateItem操作中添加一个存在检查方法。但是当前代码不起作用。我想要的逻辑是使用“包含”方法查看“ toBeAddedProgramId”是否已经存在。但是问题是,如何从User表中提取当前程序ID列表,以及如何使程序ID列表成为“列表”类型(因为contains方法仅采用String set和String)。

我希望这个问题有意义。非常感谢你们。

最好,哈里森

amazon-web-services amazon-dynamodb aws-appsync

4
推荐指数
1
解决办法
1265
查看次数

在 AWS AppSync 上创建关系的突变

我一直在尝试运行一个突变来创建与两个不同类型的关系,但没有太大成功。

** 架构 **

(我已经使用“创建资源”在 DynamoDB 中创建表)

type Comment {
    eventId: ID!
    commentId: String!
    content: String
}

type CommentConnection {
    items: [Comment]
    nextToken: String
}

input CreateCommentInput {
    eventId: ID!
    commentId: String!
    content: String
}

input CreateEventInput {
    id: ID!
    name: String
    where: String
    when: String
    description: String
}

input DeleteCommentInput {
    eventId: ID!
}

input DeleteEventInput {
    id: ID!
}

type Event {
    id: ID!
    name: String
    where: String
    when: String
    description: String
    comments(limit: Int, nextToken: String): CommentConnection
} …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services graphql aws-appsync

4
推荐指数
1
解决办法
3695
查看次数

针对 Cognito 用户的 AWS AppSync 事件订阅过滤

我有以下架构:

input CreateEventInput {
    userID: String!
    eventID: ID!
    type: String!
    data: String
    dateTime: AWSDateTime!
}

type Mutation {
    createEvent(input: CreateEventInput!): event
}

type Subscription {
    onCreateEvent(): event
        @aws_subscribe(mutations: ["createEvent"])
Run Code Online (Sandbox Code Playgroud)

createEvent解析器设置userID,如:

"key" : {
        "userID" : $util.dynamodb.toDynamoDBJson($context.identity.username),
        "eventID" : $util.dynamodb.toDynamoDBJson($util.autoId())
    }
Run Code Online (Sandbox Code Playgroud)

我想限制订阅,以便只记录userID = $context.identity.username返回给用户的位置。

有谁知道如何设置?我想我需要一个关于订阅的解析器,但我找不到一个明确的例子,你有一个主分区键 ( userID) 和主排序键 ( eventID)。

我真的很感激任何帮助或指导。如果需要,我可以更改架构或数据库。

更新

我相信我可以将订阅响应映射模板设置为:

#if(${context.identity.username} != ${context.arguments.userID})
    $utils.unauthorized()
#else
##User is authorized, but we return null to continue
    null
#end
Run Code Online (Sandbox Code Playgroud)

但是,我不知道在请求映射模板中放什么。

amazon-dynamodb amazon-cognito aws-appsync aws-amplify appsync-apollo-client

4
推荐指数
1
解决办法
2700
查看次数

AWS Amplify:当资源已被部分删除时,如何删除环境?

TL; DR:在控制台中手动删除了服务的某些资源后,如何删除放大环境?

因此,我上了蛋头课程,学习了AWS Amplify CLI。不幸的是,它没有教您如何删除环境(但是,它很棒!)。然后我的Google搜索说您将必须手动删除资源。我尝试(/做过)我所使用的资源。我删除了CLI的用户帐户(???),“删除”了cognito用户池(仍然显示在中amplify status),删除了DynamoDB和AppSync API(也仍然显示了)。

现在,正如我在跑步时提到的那样amplify status

| Category | Resource name   | Operation | Provider plugin   |
| -------- | --------------- | --------- | ----------------- |
| Auth     | cognito559c5953 | No Change | awscloudformation |
| Api      | AmplifyTodoApp  | No Change | awscloudformation |
Run Code Online (Sandbox Code Playgroud)

我想知道-因为我以为我删除了它们-它们仍然存在吗?

所以我用谷歌搜索了更多。现在事实证明,还有amplify delete一条命令会自动删除与您的放大项目关联的所有资源。由于我删除了用于该项目的帐户,因此该命令将引发:

The security token included in the request is invalid.
Run Code Online (Sandbox Code Playgroud)

没有用户,有什么办法可以删除这些资源?这些资源是否仍然在线(因为我手动删除了它们,并且它们没有在线显示在控制台中-即使在CloudFront控制台中)?还是我必须删除整个AWS账户?对于这些资源,我不想一天花大价钱。

编辑:我也删除了S3存储桶。

编辑2:因此,我设法使用了另一个配置文件(通过更改local-aws-info.json),所以我不再遇到安全请求失败的错误。现在我得到了错误:

Missing region in config …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services amazon-cloudfront amazon-cognito aws-appsync aws-amplify

4
推荐指数
2
解决办法
3127
查看次数