aws-amplify / aws-amplify/amplify-cli

amplify pull with parameters behind a proxy failed.

Open
#8,536 3 comments 0 reactions 0 assignees View on GitHub
bug p4 platform
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### Before opening, please confirm:

- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-cli/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-cli/blob/master/CONTRIBUTING.md#bug-reports).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

### How did you install the Amplify CLI?

npm

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

14.18.0

### Amplify CLI Version

6.3.1

### What operating system are you using?

Amazon Linux 2(Docker Desktop for Windows - wsl2)

### Amplify Categories

interactions

### Amplify Commands

pull

### Describe the bug

To get the remote environment, I ran the following `amplify pull`(with parameters) command behind a proxy.
This command has returned error. The result was that below stack.

```bash
$ env | grep -iE "^http[s]"
http_proxy=http://xxx.xxx.xxx:3128
https_proxy=http://xxx.xxx.xxx:3128
HTTP_PROXY=http://xxx.xxx.xxx:3128
HTTPS_PROXY=http://xxx.xxx.xxx:3128

$ amplify pull --appId xxxxxx --envName dev
Failed to pull the backend.
request to https://e7auv6no3g.execute-api.us-east-1.amazonaws.com/wave3Prod/AppState/?appId=xxxxxx failed, reason: connect ECONNREFUSED 13.35.70.87:443
FetchError: request to https://e7auv6no3g.execute-api.us-east-1.amazonaws.com/wave3Prod/AppState/?appId=xxxxxx failed, reason: connect ECONNREFUSED 13.35.70.87:443
at ClientRequest. (/usr/lib/node_modules/@aws-amplify/cli/node_modules/node-fetch/lib/index.js:1483:11)
at ClientRequest.emit (events.js:400:28)
at ClientRequest.emit (domain.js:475:12)
at TLSSocket.socketErrorListener (_http_client.js:475:9)
at TLSSocket.emit (events.js:400:28)
at TLSSocket.emit (domain.js:475:12)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
```

However, `amplify init` and `amplify pull` without parameters works.

### Expected behavior

Even in behind a proxy, `amplify pull`(with parameters) command completes successfully

### Reproduction steps

Only run the `amplify pull`(with parameters) command below behind the proxy.
```bash
$ amplify pull --appId xxxxxx --envName dev
Failed to pull the backend.
....
```

But execute `amplify init` and `amplify pull` without parameters in Interactive works fine.
```bash
$ amplify pull
? Select the authentication method you want to use: (Use arrow keys)
❯ AWS profile
AWS access keys
```

### GraphQL schema(s)

_No response_

### Log output

```
# Put your logs below this line

```

### Additional information

Looking the error log, this error occurred at calling request by node-fetch.
```
at ClientRequest. (/usr/lib/node_modules/@aws-amplify/cli/node_modules/node-fetch/lib/index.js:1483:11)
```

I found the location of the node-fetch call that was causing the error when `amplify pull`(with parameters) and applied the following patch.

`$ diff -u /usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/utils/admin-helpers.js{.original,}`

```js
--- /usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/utils/admin-helpers.js.original 2021-10-24 22:47:37.009666700 +0000
+++ /usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/utils/admin-helpers.js 2021-10-24 22:49:02.369666700 +0000
@@ -44,10 +44,12 @@
return await getAdminStsCredentials(idToken, region);
}
exports.getTempCredsWithAdminTokens = getTempCredsWithAdminTokens;
+const hpa = __importDefault(require("https-proxy-agent"));
+const hpa2 = new hpa.default("http://xxx.xxx.xxx.xxx:3128");
async function getAdminAppState(appId, region) {
var _a;
const appStateBaseUrl = (_a = process.env.AMPLIFY_CLI_APPSTATE_BASE_URL) !== null && _a !== void 0 ? _a : exports.adminBackendMap[region].appStateUrl;
- const res = await node_fetch_1.default(`${appStateBaseUrl}/AppState/?appId=${appId}`);
+ const res = await node_fetch_1.default(`${appStateBaseUrl}/AppState/?appId=${appId}`, {agent: hpa2});
return res.json();
}
async function getAdminCognitoCredentials(idToken, identityId, region) {
@@ -186,4 +188,4 @@
appStateUrl: 'https://3ne6skqg0g.execute-api.us-west-2.amazonaws.com/wave4Prod',
},
};
```

and execute `amplify pull --appId xxxxxx --envName dev` command then it works.
```
? Select the authentication method you want to use: (Use arrow keys)
❯ AWS profile
AWS access keys
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.