aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

Elasticsearch Geo Location Setup Issue #3200

Closed Rafcin closed 4 years ago

Rafcin commented 4 years ago

Note: If your issue/bug is regarding the AWS Amplify Console service, please log it in the Amplify Console GitHub Issue Tracker

Describe the bug The problem is when following the guide from https://aws-amplify.github.io/docs/cli-toolchain/graphql?sdk=js#searchable about elasticsearch and geo location, I run into trouble when I create my resolvers and custom resource.

The CLI complains with:

Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: The following resource(s) failed to update: [CustomResourcesjson].

CustomResourcesjson-{numbers} was not successfully updated. Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: The following resource(s) failed to create: [searchByDistRestaurants].

Resource Name: searchByDistRestaurants (AWS::AppSync::Resolver)
Event Type: create
Reason: The specified key does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchKey; Request ID: {ID}; S3 Extended Request ID: {id}=)

✖ An error occurred when pushing the resources to the cloud

Amplify CLI Version 4.11.0 To Reproduce

  1. Add searchable to your schema
  2. Amplify Push
  3. Create resolvers
  4. Create resource
  5. Push

Here are my setups: Schema:

type restaurant @model @searchable
  @auth(rules: [

    { allow: owner, operations: [read, create, update, delete] },

    { allow: public },

    { allow: groups, groups: ["Admin"], operations: [read, create, update, delete] },

    { allow: groups, groups: ["RestaurantUser"], operations: [create, read] },

    { allow: groups, groups: ["User"], operations: [read] }

  ]) {
  id: ID!
  restaurantName: String!
 ....
}

type Location @model @auth(rules: [

    { allow: public }

  ]) {
  lat: Float
  lon: Float
}
input LocationInput {
  lat: Float
  lon: Float
}

type Query {
  searchByDistance(location: LocationInput!, km: Int): RestaurantConnection
}

type RestaurantConnection {
  items: [restaurant]
  total: Int
  nextToken: String
}

type restaurantHours @model {
  id: ID!
  day: String!
  hour: String!
}

The Resolver & Resource

        "searchByDistance": {
              "Type": "AWS::AppSync::Resolver",
              "Properties": {
                "ApiId": {
                  "Ref": "AppSyncApiId"
                },
                "DataSourceName": "ElasticSearchDomain",
                "TypeName": "Query",
                "FieldName": "searchByDistance",
                "RequestMappingTemplateS3Location": {
                  "Fn::Sub": [
                    "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.searchByDistance.req.vtl",
                    {
                      "S3DeploymentBucket": {
                        "Ref": "S3DeploymentBucket"
                      },
                      "S3DeploymentRootKey": {
                        "Ref": "S3DeploymentRootKey"
                      }
                    }
                  ]
                },
                "ResponseMappingTemplateS3Location": {
                  "Fn::Sub": [
                    "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.searchByDistance.res.vtl",
                    {
                      "S3DeploymentBucket": {
                        "Ref": "S3DeploymentBucket"
                      },
                      "S3DeploymentRootKey": {
                        "Ref": "S3DeploymentRootKey"
                      }
                    }
                  ]
                }
              }
            }

## Query.searchByDistance.req.vtl
## Objects of type restaurant will be stored in the /restaurant index

#set( $indexPath = "/restaurant/doc/_search" )
#set( $distance = $util.defaultIfNull($ctx.args.km, 200) )
{
    "version": "2017-02-28",
    "operation": "GET",
    "path": "$indexPath.toLowerCase()",
    "params": {
        "body": {
            "query": {
                "bool" : {
                    "filter" : {
                        "geo_distance" : {
                            "distance" : "${distance}km",
                            "coordinates" : $util.toJson($ctx.args.location)
                        },

                    }
                }
            }
        }
    }
}

## Query.searchByDistance.res.vtl

#set( $items = [] )
#foreach( $entry in $context.result.hits.hits )
  #if( !$foreach.hasNext )
    #set( $nextToken = "$entry.sort.get(0)" )
  #end
  $util.qr($items.add($entry.get("_source")))
#end
$util.toJson({
  "items": $items,
  "total": $ctx.result.hits.total,
  "nextToken": $nextToken
})
Rafcin commented 4 years ago

If you need any logs or anything else let me know. I'll be around.

Rafcin commented 4 years ago

This also occurs with 4.12.0

Rafcin commented 4 years ago

I've tried to update the s3 paths and change a few things in the resolvers. Still no luck.

Rafcin commented 4 years ago

Resolved.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.