aws-sigv4-ec2meta
v1.0.2
Published
Signs an http(s) request options object with AWS Signature Version 4 headers and returns them
Downloads
3
Maintainers
Readme
aws-sigv4-ec2meta
Signs an http(s) request options object with AWS Signature Version 4 headers and returns them
Sample Usage
Use the signAWS
function provided by the module to add the appropriate cryptographically secure headers to an http or https request options object. This function accepts an options object as the first parameter and a callback as the second parameter.
checkout repo
npm install
let signAWS = require('./aws-sigv4-ec2metadata/index.js');
let https = require('https');
let deleteOpts = {
host: 'exampleapi.execute-api.us-west-2.amazonaws.com',
path: '/api/configs/1',
method: 'DELETE'
};
signAWS(deleteOpts, (signedOpts) => {
let req = https.request(signedOpts, (res) => {
let body = [];
res.on('data', (d) => {
body.push(d);
});
res.on('end', () => console.log(body.join('')));
});
req.on('error', console.error);
req.end();
});
Testing Locally
To test locally, use the aws-mock-metadata library to simulate an ec2 instance profile environment.
Steps to Install on OSX
- Boto dependency
sudo easy_install pip
sudo pip install boto
- Clone https://github.com/dump247/aws-mock-metadata.git
- Configure aws-mock-metadata
- Create a
server.conf
file in the root of the aws-mock-metadata folder (see server.conf.sample for an example of this) - Replace the **** values in this file with your AWS user access key and secret key
- Create a
- Start the mock metadata server by running
./bin/server-macos
- Verify the server is running and configured correctly by hitting the metadata url in your local browser
Note that your user account and/or ec2 instance profile role must have the execute-api
policy for a given resource in order to query AWS_IAM protected API methods.