aws-samples / simple-nft-marketplace

This project provides sample codes to build a simple NFT marketplace with Amazon Managed Blockchain.
MIT No Attribution
95 stars 48 forks source link

Failed to load resource: the server responded with a status of 502 () #44

Open Ed-Marcavage opened 2 years ago

Ed-Marcavage commented 2 years ago

Everything in the app is working beside the following:

The problem arises in the Eth Deposit section of Docs: https://github.com/aws-samples/simple-nft-marketplace/blob/main/docs/en/DOCS_04_FRONTEND.md

After I click the "Account" button in the upper right-hand corner of the page I do not see the following information: Address: Public Address Balance: The balance of deposited Ethereum Private Key: The private key of the wallet. Display by pressing the "Retrieve" button

Rather, I see "Loading ..." see below:

Screen Shot 2022-10-11 at 9 38 39 PM

In the console I get the following error:

Failed to load resource: the server responded with a status of 502 ()
vue.runtime.esm.js:3019 Error: Request failed with status code 502
    at e.exports (createError.js:16:15)
    at e.exports (settle.js:17:12)
    at XMLHttpRequest.S (xhr.js:66:7)

Im not sure if its an error in the front end, env variables, or one of my AWS apps. Please help as I am very excited about this repo and already learned a ton!

Ed-Marcavage commented 2 years ago

Also, the link with the api gateway (https://___APIgatewayID___.execute-api.us-east-1.amazonaws.com/prod/account) returns: {"message":"Unauthorized"}

tbrand commented 2 years ago

It seems that you are not logged in. Did you create your account first? If so, did you login to the system? Also, you can confirm your account existence on Congito on AWS Management Console. Did you provide user pool id environment variables to the frontend? Please check the above. Thanks for trying!

Ed-Marcavage commented 2 years ago

Yes, I can see my created account in AWS Congito, and all 4 environment variables:

cat <<EOF > .env.local
VUE_APP_AWS_REGION=<region>
VUE_APP_API_ENDPOINT=<api-endpoint>
VUE_APP_USER_POOL_ID=<user-pool>
VUE_APP_USER_POOL_WEB_CLIENT_ID=<web-client>
EOF

... have been successfully uploaded. I know they were successful because I got an error my pool_id was not the correct len because I mixed up Pool_Id and web-client id, then the page rendered.

Ed-Marcavage commented 2 years ago

Could it be a problem with my browser not allowing HTTP connects? Or with cloudfront?

Ed-Marcavage commented 2 years ago
Screen Shot 2022-10-12 at 9 20 08 PM

As seen above, it appears that my username is successfully being pulled from the Vue front end, however, my account is not. Im unsure how to solve this problem

Ed-Marcavage commented 2 years ago
Screen Shot 2022-10-12 at 9 22 22 PM

Screen Shot 2022-10-12 at 9 22 34 PM

I added this snippet in view to verify my username is being pulled, however when I add the snippet seen below for my account, i get an error:

Screen Shot 2022-10-12 at 9 23 40 PM

Screen Shot 2022-10-12 at 9 24 02 PM

tbrand commented 2 years ago

Could it be a problem with my browser not allowing HTTP connects? Or with cloudfront?

Login request directly connect to Cognito, not via CloudFront. So that's not a problem. (Both of them are connected via HTTP"S") Additionally, your frontend was rendered correctly. So there is no problem with CloudFront.

I added this snippet in view to verify my username is being pulled

Agree

however when I add the snippet seen below for my account, i get an error

The account info is fetched by API Gateway. That means your request was stacked at here. So we should investigate why the API Gateway didn't respond correctly. The simple way to do the investigation is checking the lambda function's log. getAccount.ts should be invoked by API Gateway when you request your account info. So go to AWS Management Console, find the getAccount function (the name of the function is with random strings which was added by CDK. but the name contains GetAccount prefix.), visit Monitor tab, and click View Logs.

If the log group exists, that means your API Gateway invoked the Lambda function correctly. If not, it was failed. Please paste your raw logs (concealing personal stuff if you need) if your could. Thanks!

Ed-Marcavage commented 2 years ago

Thanks sm for the help! Here is the log from cloudwatch:

2022-10-12T22:22:55.922-04:00 | START RequestId: 682966a4-89e4-4b01-967e-dee7f1e1f7a2 Version: $LATEST   | 2022-10-12T22:23:02.762-04:00 | 2022-10-13T02:23:02.725Z 682966a4-89e4-4b01-967e-dee7f1e1f7a2 ERROR (node:9) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use node --trace-deprecation ... to show where the warning was created)   | 2022-10-12T22:23:02.822-04:00 | 2022-10-13T02:23:02.803Z 682966a4-89e4-4b01-967e-dee7f1e1f7a2 ERROR Invoke Error {"errorType":"Error","errorMessage":"[aws-ethjs-provider-http] CONNECTION ERROR: Couldn't connect to node 'nd-vp3yjzncinhb7dxxlxjt7r3cwe.ethereum.managedblockchain.us-east-1.amazonaws.com': {\n \"message\": \"Header host contains invalid value\",\n \"code\": \"InvalidHeader\",\n \"time\": \"2022-10-13T02:23:02.725Z\"\n}","stack":["Error: [aws-ethjs-provider-http] CONNECTION ERROR: Couldn't connect to node 'nd-vp3yjzncinhb7dxxlxjt7r3cwe.ethereum.managedblockchain.us-east-1.amazonaws.com': {"," \"message\": \"Header host contains invalid value\","," \"code\": \"InvalidHeader\","," \"time\": \"2022-10-13T02:23:02.725Z\"","}"," at Object._fireError (/var/task/index.js:29868:17)"," at sendTxCallback (/var/task/index.js:53756:26)"," at /var/task/index.js:47537:18"," at AWSHttpProvider.send (/var/task/index.js:41738:13)"," at RequestManager2.RequestManager.send (/var/task/index.js:47465:23)"," at sendRequest (/var/task/index.js:53820:41)"," at Eth2.send [as getBalance] (/var/task/index.js:53843:11)"," at Runtime.exports.handler (/var/task/index.js:118171:37)"," at processTicksAndRejections (internal/process/task_queues.js:95:5)"]}   | 2022-10-12T22:23:02.883-04:00 | END RequestId: 682966a4-89e4-4b01-967e-dee7f1e1f7a2   | 2022-10-12T22:23:02.883-04:00 | REPORT RequestId: 682966a4-89e4-4b01-967e-dee7f1e1f7a2 Duration: 6961.22 ms Billed Duration: 6962 ms Memory Size: 128 MB Max Memory Used: 116 MB Init Duration: 604.90 ms XRAY TraceId: 1-6347767f-00a8eba459f9c4d10672e483 SegmentId: 66330d305a21be2b Sampled: true   |  


Ed-Marcavage commented 2 years ago

So it seems it cannot connect to AMB, i did enter export AMB_HTTP_ENDPOINT='https://.ethereum.managedblockchain..amazonaws.com' (with my nodes HTTP endpoit)

Ed-Marcavage commented 2 years ago
Screen Shot 2022-10-12 at 11 19 20 PM

I believe i found the possible error in my code, I have "n-ethereum-ropsten" as the chainID and not n-ethereum-goerli,

let me change this, re-bootstrap my CDK and test

Ed-Marcavage commented 2 years ago

Just curious, when you change a file in /provision is there a way to avoid having to run CDK bootstrap and cdk deploy SimpleNftMarketplaceStack again?

Ed-Marcavage commented 2 years ago

Changed the NetworkID accordingly, got the same error:

2022-10-12T23:44:21.616-04:00 | START RequestId: 0b6334ac-9935-414a-9ca6-2d85f4987d15 Version: $LATEST
-- | --
  | 2022-10-12T23:44:28.375-04:00 | 2022-10-13T03:44:28.374Z 0b6334ac-9935-414a-9ca6-2d85f4987d15 ERROR (node:9) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created)
  | 2022-10-12T23:44:28.394-04:00 | 2022-10-13T03:44:28.394Z 0b6334ac-9935-414a-9ca6-2d85f4987d15 ERROR Invoke Error {"errorType":"Error","errorMessage":"[aws-ethjs-provider-http] CONNECTION ERROR: Couldn't connect to node 'nd-vp3yjzncinhb7dxxlxjt7r3cwe.ethereum.managedblockchain.us-east-1.amazonaws.com': {\n \"message\": \"Header host contains invalid value\",\n \"code\": \"InvalidHeader\",\n \"time\": \"2022-10-13T03:44:28.373Z\"\n}","stack":["Error: [aws-ethjs-provider-http] CONNECTION ERROR: Couldn't connect to node 'nd-vp3yjzncinhb7dxxlxjt7r3cwe.ethereum.managedblockchain.us-east-1.amazonaws.com': {"," \"message\": \"Header host contains invalid value\","," \"code\": \"InvalidHeader\","," \"time\": \"2022-10-13T03:44:28.373Z\"","}"," at Object._fireError (/var/task/index.js:29868:17)"," at sendTxCallback (/var/task/index.js:53756:26)"," at /var/task/index.js:47537:18"," at AWSHttpProvider.send (/var/task/index.js:41738:13)"," at RequestManager2.RequestManager.send (/var/task/index.js:47465:23)"," at sendRequest (/var/task/index.js:53820:41)"," at Eth2.send [as getBalance] (/var/task/index.js:53843:11)"," at Runtime.exports.handler (/var/task/index.js:118171:37)"," at processTicksAndRejections (internal/process/task_queues.js:95:5)"]}
  | 2022-10-12T23:44:28.414-04:00 | END RequestId: 0b6334ac-9935-414a-9ca6-2d85f4987d15
  | 2022-10-12T23:44:28.414-04:00 | REPORT RequestId: 0b6334ac-9935-414a-9ca6-2d85f4987d15 Duration: 6798.28 ms Billed Duration: 6799 ms Memory Size: 128 MB Max Memory Used: 116 MB Init Duration: 577.42 ms XRAY TraceId: 1-63478994-4ddcfbbf6d0b5abc6940321b SegmentId: 6a8bbd2c4ed8fa7e Sampled: true
Ed-Marcavage commented 2 years ago

"errorType": "Error", "errorMessage": "[aws-ethjs-provider-http] CONNECTION ERROR: Couldn't connect to node 'nd-_____nodeID____.ethereum.managedblockchain.us-east-1.amazonaws.com': {\n \"message\": \"Header host contains invalid value\",\n \"code\": \"InvalidHeader\",\n \"time\": \"2022-10-23T17:20:07.087Z\"\n}",