Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Clean up getPublicIp() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jplock committed May 29, 2019
1 parent 723174c commit 70ec7f1
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 111 deletions.
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"test": "npx sls invoke -f s3"
},
"devDependencies": {
"aws-sdk": "2.290.0",
"serverless": "1.41.0",
"aws-sdk": "2.465.0",
"serverless": "1.44.1",
"serverless-vpc-plugin": "smoketurner/serverless-vpc-plugin#master"
}
}
33 changes: 12 additions & 21 deletions example/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,19 @@ const { BUCKET_NAME } = process.env;
* @return {Promise}
*/
function getPublicIp() {
const options = {
host: 'api.ipify.org',
port: 80,
path: '/',
};
return new Promise((resolve, reject) => {
const options = {
host: 'api.ipify.org',
port: 80,
path: '/',
};
http
.get(options, res => {
res.setEncoding('utf8');

let body = '';
res.on('data', chunk => {
body += chunk;
});

res.on('end', () => {
resolve(body);
});
})
.on('error', err => {
reject(err);
});
const req = http.get(options, res => {
const buffers = [];
res.on('data', data => buffers.push(data));
res.once('end', () => resolve(Buffer.concat(buffers).toString()));
res.once('error', reject);
});
req.once('error', reject);
});
}

Expand Down
2 changes: 1 addition & 1 deletion example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ service: sls-vpc-example

provider:
name: aws
runtime: nodejs8.10
runtime: nodejs10.x
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'us-east-1'}
versionFunctions: false
Expand Down
Loading

0 comments on commit 70ec7f1

Please sign in to comment.