开发者社区> 镜像站> NPM> @perform/dazn-carl
@perform/dazn-carl
A bit like curl, but for AWS. Can be used as npm module or on the command line to make requests to an API Gateway protected via IAM.
Last updated 2 years ago by automation-drone .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @perform/dazn-carl 
SYNC missed versions from official npm registry.

Carl

A bit like curl, but for AWS. Can be used as npm module or on the command line to make requests to an API Gateway protected via IAM.

It assumes the given role, then uses aws4 to create a signed request, which is sent via the request module.

Prerequisites

You must have the following environment variables available: AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID.

The user represented by these credentials, Must have the right to assume the given role. In addition they must included in the list of trusted entites in the role itself. See here for more information.

Using as a js module

const carl = require('@perform/dazn-carl')
carl({
    url: 'url-of-api.blah.com',
    method: 'POST',
    json: true,
    body: {
        some: 'stuff',
        more: 'stuff'
    },
    aws: {
        RoleArn: 'arn:aws:iam::[ACCOUNT_ID]:role/[ROLE_NAME]'
    }
}).then(response => {
    // response object as returned from request module
}).catch(err => {
    // error from request module
});

Full Options

method = 'GET', url, headers = {}, body = null, json = false, aws: { DurationSeconds = 3600, RoleSessionName = 'Carl', region = 'eu-west-2', service = 'execute-api', RoleArn, },

  • method The HTTP method (default: 'GET')
  • url The full url to call
  • headers Map of additonal headers to pass
  • json Set to true to send json payload (will also update headers)
  • body Body content as string (or object if json === true)
  • aws Object
    • aws.RoleArn arn of the role to assume (REQUIRED)
    • aws.RoleSessionName passed to STS, can be anything you like (default 'Carl')
    • aws.region The AWS region the API is in (default 'eu-west-1')

Using as a cli module

(Assumes that you have installed globally or you have ./node_modules/.bin) in your $PATH)

The options are deliberately similar to curl in the hop that this makes things easier:

carl -H 'Content-Type: application/json' \
-d '{"context":"context","chapter":"chapter","pipelineName":"pipelineName","buildNumber":"buildNumber","pipelineStep":"pipelineStep","environment":"environment","message":{"text":"messageText","error":false}}' \
--role arn:aws:iam::082876741967:role/invoke_api_gateway \
-X POST https://logger.district.tube.indaznlab.com/

Full options

Usage: carl [options] url

Options:
  -V, --version               output the version number
  -X, --request [method]      HTTP Method to use
  -H, --header [name: value]  Add HTTP Header
  -d, --data [body]           Request body
  R, --role <role>            ARN of the role to assume
  -h, --help                  output usage information

Release Process

To create a new release use npm version or yarn version from master branch only please. Then run git push && git push --tags Drone should pick up the tag and publish it to npm

Current Tags

  • 1.1.2                                ...           latest (2 years ago)

7 Versions

  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0-beta2                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
Maintainers (199)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (6)
Dependents (0)
None