在代理后面运行节点

时间:2019-05-08 05:39:44

标签: node.js amazon-web-services

我有一个简单的代码来检测aws帐户ID,并检查它是否与json文件中的ID相匹配

$ cat sample.json

{
  "account_id": "123456789012",
  "name": "foo"
}

nodejs代码

#!/usr/bin/env node

const fs = require('fs');
const util = require('util');
const aws = require('aws-sdk');

const sts = new aws.STS();

const file = 'sample.json';
const content = fs.readFileSync(file);
const jsonContent = JSON.parse(content);

sts.getCallerIdentity({}, (err, data) => {
  if (err) {
    console.log('can not get aws account id');
    process.exit(-1);
  } else if (data.Account !== jsonContent.account_id) {
    console.log(util.format('aws account id does not match its configuration file %s , exist ...', file));
    process.exit(-1);
  } else {
    console.log('account matched');
  }
});

如果我直接在笔记本电脑上运行它,则可以显示“帐户匹配”

但是当我在带有公司代理(I can curl public url in docker, so the proxy setting is no issue here)的docker中运行时,它失败并显示错误

can not get aws account id

npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! sample@1.0.0 account: `node a.js`
npm ERR! Exit status 255
npm ERR!
npm ERR! Failed at the sample@1.0.0 account script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-05-08T05_45_56_807Z-debug.log

/root/.npm/_logs/2019-05-08T05_45_56_807Z-debug.log中没有有用的信息

我可以在运行容器中curl公开URL。

bash-4.3# curl www.google.com|more
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   676    0   676    0     0   3907      0 --:--:-- --:--:-- --:--:--  3885
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-AU"><head><meta content="text/
...

所以我想这是因为代理阻止了访问。我应该怎么做才能解决它?

0 个答案:

没有答案