I have a simple code to detect the aws account id and check if it matches the id in a json file
$ cat sample.json
{
"account_id": "123456789012",
"name": "foo"
}
the nodejs code
#!/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');
}
});
If I run it directly on my laptop, it works, show "account matched"
But when I run in docker with corporate proxy (I can curl public url in docker, so the proxy setting is no issue here
), it is failed with error
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
No useful information in /root/.npm/_logs/2019-05-08T05_45_56_807Z-debug.log
I can curl
public url in the running container.
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/
...
So I guess it is because the proxy blocked the access. What should I do to fix it?