aws-amplify / aws-amplify/amplify-cli
Mocking a function that uses ECSClient fails with circular JSON error
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### How did you install the Amplify CLI?
npm
### If applicable, what version of Node.js are you using?
v18.16.1
### Amplify CLI Version
10.7.3
### What operating system are you using?
Ubuntu
### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes made.
### Describe the bug
I have an Amplify-created Lambda function which I plan to use to talk to my ECS deployment (among other things).
The relevant code in the Lambda is:
```js
const { ECSClient, ListClustersCommand } = require("@aws-sdk/client-ecs");
const client = new ECSClient({region: process.env.REGION});
const command = new ListClustersCommand({});
const response = await client.send(command);
```
When I run the function locally with `amplify mock function clustermanager`, the `client.send` line fails with this error:
```
(node:1179030) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'TLSSocket'
| property '_httpMessage' -> object with constructor 'ClientRequest'
--- property 'socket' closes the circle
at JSON.stringify ()
at /snapshot/repo/build/node_modules/amplify-nodejs-function-runtime-provider/lib/utils/execute.js:43:31
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `amplify --trace-warnings ...` to show where the warning was created)
```
I would expect some sort of auth error if I haven't set up authentication correctly so that the Lambda can access ECS (and part of the reason I was running it was to work out which roles/IAM I need to set up!) but this does not seem like an authentication error; it seems like a low-level bug somewhere. Since it seems to be involved with "amplify-nodejs-function-runtime-provider", I think it's some sort of Amplify CLI mocking bug.
### Expected behavior
I would expect this circular structure JSON message to not happen.
### Reproduction steps
1. `amplify function add`
2. in the function src directory, `npm install --save @aws-sdk/client-ecs`
3. in the function body, add the code above
4. `amplify mock function yourfunction`
Get the error
### Project Identifier
_No response_
### Log output
_No response_
### Additional information
_No response_
### Before submitting, please confirm:
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
Contributor guide
Assessment
This issue has not been assessed yet.