aws-amplify / amplify-cli

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

the mock service find a s3-template in a dynamodb folder and get crashed #8069

Closed yhvh009 closed 2 years ago

yhvh009 commented 3 years ago

Before opening, please confirm:

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v12.10.0

Amplify CLI Version

5.3.1

What operating system are you using?

Mac 10.14.6

Amplify Categories

storage, api

Amplify Commands

Not applicable

Describe the bug

the brief work flow of my project:

brief structure of my project:

And when I run 'amplify mock' to mock the backend and 'npm run dev' to debug the frontend. The upload process was successful and I can get the tmpUrl like "http://localhost:20005/undefined-staging/public/photos/e334f3ebc5ad661665714373ee58fc3c.jpg?X-Amz-Algorithm= " , but when request the graphql api, the mocked backend shutdown and print

error: uncaughtException: File at path: '/Users/xxx/amplify/backend/storage/dbname/s3-cloudformation-template.json' does not exist

the "dbname" is a dynamo db but not a s3bucket, so of course there's no s3-cloudformation-template.json, there's 'dbname-cloudformation-template.json' in that path.

so I don't why the mock function search for a s3template in a dynamodb folder.

Expected behavior

the mock function perform stably

Reproduction steps

  1. npm run dev
  2. amplify mock
  3. choose a photo and upload to s3bucket
  4. get the tmpurl
  5. pass the url with
    await API.graphql(graphqlOperation(gapi, {input: url}))

the mock server will shutdown and frontend get "POST http://192.168.1.83:20002/graphql net::ERR_CONNECTION_RESET"

GraphQL schema(s)

```graphql # Put schemas below this line type Query { gapi(input: String): String @function(name: "aFunction-${env}") @aws_api_key } ```

Log output

``` # Put your logs below this line I reproduce the error, but there's only these two lines 2021-08-31T17:10:46.955Z|info : amplify mock mock 2021-08-31T17:10:46.982Z|info : amplify-cli-core.banner-message/index.ts.fetch banner messages from https://aws-amplify.github.io/amplify-cli/banner-message.json({} ```

Additional information

the whole message in the terminal

amplify mock
Mock Storage endpoint is running at http://localhost:20005

GraphQL schema compiled successfully.

Edit your schema at /Users/xxx/amplify/backend/api/gqlapi/schema.graphql or place .graphql files in a directory at /Usersxxx/amplify/backend/api/gqlapi/schema
Running GraphQL codegen
✔ Generated GraphQL operations successfully and saved at src/graphql
AppSync Mock endpoint is running at http://192.168.1.83:20002
2021-08-31T17:11:03.598Z - error: uncaughtException: File at path: '/Users/xxx/amplify/backend/storage/xxx/s3-cloudformation-template.json' does not exist date=Wed Sep 01 2021 01:11:03 GMT+0800 (GMT+08:00), pid=13770, uid=501, gid=20, cwd=/Users/xxx, execPath=/Users/xxx/.amplify/bin/amplify, version=v12.22.2, argv=[/Users/xxx/.amplify/bin/amplify, /snapshot/node_modules/@aws-amplify/cli/bin/amplify, mock], rss=302694400, heapTotal=204591104, heapUsed=197142920, external=3698968, arrayBuffers=2112975, loadavg=[3.00244140625, 2.5390625, 2.3154296875], uptime=49916, trace=[column=19, file=/snapshot/node_modules/amplify-cli-core/lib/jsonUtilities.js, function=Function.readJson, line=40, method=readJson, native=false, column=62, file=/snapshot/node_modules/amplify-util-mock/lib/storage/storage.js, function=null, line=110, method=null, native=false, column=20, file=events.js, function=StorageServer.emit, line=314, method=emit, native=false, column=12, file=domain.js, function=StorageServer.EventEmitter.emit, line=483, method=emit, native=false, column=18, file=/snapshot/node_modules/amplify-storage-simulator/lib/server/S3server.js, function=StorageServer.handleRequestPut, line=217, method=handleRequestPut, native=false, column=18, file=/snapshot/node_modules/amplify-storage-simulator/lib/server/S3server.js, function=StorageServer.handleRequestAll, line=85, method=handleRequestAll, native=false, column=5, file=/snapshot/node_modules/express/lib/router/layer.js, function=Layer.handle [as handle_request], line=95, method=handle [as handle_request], native=false, column=13, file=/snapshot/node_modules/express/lib/router/index.js, function=trim_prefix, line=317, method=null, native=false, column=7, file=/snapshot/node_modules/express/lib/router/index.js, function=null, line=284, method=null, native=false, column=12, file=/snapshot/node_modules/express/lib/router/index.js, function=Function.process_params, line=335, method=process_params, native=false, column=10, file=/snapshot/node_modules/express/lib/router/index.js, function=next, line=275, method=null, native=false, column=16, file=/snapshot/node_modules/serve-static/index.js, function=serveStatic, line=75, method=null, native=false, column=5, file=/snapshot/node_modules/express/lib/router/layer.js, function=Layer.handle [as handle_request], line=95, method=handle [as handle_request], native=false, column=13, file=/snapshot/node_modules/express/lib/router/index.js, function=trim_prefix, line=317, method=null, native=false, column=7, file=/snapshot/node_modules/express/lib/router/index.js, function=null, line=284, method=null, native=false, column=12, file=/snapshot/node_modules/express/lib/router/index.js, function=Function.process_params, line=335, method=process_params, native=false, column=10, file=/snapshot/node_modules/express/lib/router/index.js, function=next, line=275, method=null, native=false, column=5, file=/snapshot/node_modules/body-parser/lib/read.js, function=null, line=130, method=null, native=false, column=16, file=/snapshot/node_modules/raw-body/index.js, function=invokeCallback, line=224, method=null, native=false, column=7, file=/snapshot/node_modules/raw-body/index.js, function=done, line=213, method=null, native=false, column=7, file=/snapshot/node_modules/raw-body/index.js, function=IncomingMessage.onEnd, line=273, method=onEnd, native=false, column=20, file=events.js, function=IncomingMessage.emit, line=314, method=emit, native=false, column=12, file=domain.js, function=IncomingMessage.EventEmitter.emit, line=483, method=emit, native=false, column=12, file=_stream_readable.js, function=endReadableNT, line=1241, method=null, native=false, column=21, file=internal/process/task_queues.js, function=processTicksAndRejections, line=84, method=null, native=false], stack=[Error: File at path: '/Users/xxx/amplify/backend/storage/xxx/s3-cloudformation-template.json' does not exist,     at Function.readJson (/snapshot/node_modules/amplify-cli-core/lib/jsonUtilities.js:40:19),     at StorageServer.<anonymous> (/snapshot/node_modules/amplify-util-mock/lib/storage/storage.js:110:62),     at StorageServer.emit (events.js:314:20),     at StorageServer.EventEmitter.emit (domain.js:483:12),     at StorageServer.handleRequestPut (/snapshot/node_modules/amplify-storage-simulator/lib/server/S3server.js:217:18),     at StorageServer.handleRequestAll (/snapshot/node_modules/amplify-storage-simulator/lib/server/S3server.js:85:18),     at Layer.handle [as handle_request] (/snapshot/node_modules/express/lib/router/layer.js:95:5),     at trim_prefix (/snapshot/node_modules/express/lib/router/index.js:317:13),     at /snapshot/node_modules/express/lib/router/index.js:284:7,     at Function.process_params (/snapshot/node_modules/express/lib/router/index.js:335:12),     at next (/snapshot/node_modules/express/lib/router/index.js:275:10),     at serveStatic (/snapshot/node_modules/serve-static/index.js:75:16),     at Layer.handle [as handle_request] (/snapshot/node_modules/express/lib/router/layer.js:95:5),     at trim_prefix (/snapshot/node_modules/express/lib/router/index.js:317:13),     at /snapshot/node_modules/express/lib/router/index.js:284:7,     at Function.process_params (/snapshot/node_modules/express/lib/router/index.js:335:12),     at next (/snapshot/node_modules/express/lib/router/index.js:275:10),     at /snapshot/node_modules/body-parser/lib/read.js:130:5,     at invokeCallback (/snapshot/node_modules/raw-body/index.js:224:16),     at done (/snapshot/node_modules/raw-body/index.js:213:7),     at IncomingMessage.onEnd (/snapshot/node_modules/raw-body/index.js:273:7),     at IncomingMessage.emit (events.js:314:20),     at IncomingMessage.EventEmitter.emit (domain.js:483:12),     at endReadableNT (_stream_readable.js:1241:12),     at processTicksAndRejections (internal/process/task_queues.js:84:21)]
cjihrig commented 3 years ago

Would you be willing to share your Amplify project via email to amplify-cli@amazon.com?

yhvh009 commented 3 years ago

Would you be willing to share your Amplify project via email to amplify-cli@amazon.com?

sent by ji****an@gmail.com

danielleadams commented 3 years ago

Hi @yhvh009 - we received your email and someone is looking at it for you. We will follow up when we have an update.

yhvh009 commented 3 years ago

Hi @yhvh009 - we received your email and someone is looking at it for you. We will follow up when we have an update.

Ok, Thanks a lot

danielleadams commented 3 years ago

@yhvh009 can you go through the steps you went through to create your function and storage resources? I'm able to reproduce the error, but I'd like to understand how your app got into this state. Thanks!

yhvh009 commented 3 years ago

@yhvh009 can you go through the steps you went through to create your function and storage resources? I'm able to reproduce the error, but I'd like to understand how your app got into this state. Thanks!

Sorry, I'm not sure about that, I did plenty of actions, mostly on the terminal using cli, and I thought I've tried delete the db and recreate it when I first met this error, but still got the problem after some time.

josefaidt commented 3 years ago

Hey @yhvh009 :wave: apologies for the delay! Do you see a bucketName parameter in your storage's parameters.json file? This file is located at amplify/backend/storage/<resource-name>/parameters.json. I'm curious about the undefined that's shown in the URL from your original post

yhvh009 commented 3 years ago

Hey @yhvh009 👋 apologies for the delay! Do you see a bucketName parameter in your storage's parameters.json file? This file is located at amplify/backend/storage/<resource-name>/parameters.json. I'm curious about the undefined that's shown in the URL from your original post

nope, there's only three params in the json file of the dynamodb storage:

{
    "tableName": "XXXX",
    "partitionKeyName": "s3Key",
    "partitionKeyType": "S"
}

on the other hand, there's a bucketname in the s3 bucket storage, and lots of params related to s3xxxx

josefaidt commented 2 years ago

Hey @yhvh009 :wave: apologies for the delay again. Are you still experiencing this issue with the latest version of the CLI? I'm unable to reproduce this behavior in a new project.

josefaidt commented 2 years ago

Hey @yhvh009 :wave: just wanted to follow-up on this one and see if you were still experiencing this issue with the latest version of the CLI?