How to use the aws-sdk.Lambda function in aws-sdk

To help you get started, we’ve selected a few aws-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github architect / architect / src / create / aws / create-ws-router / create / route.js View on Github external
module.exports = function route({api, env, name, region, account, RouteKey}, callback) {

  let gateway = new aws.ApiGatewayV2({region})
  let lambda = new aws.Lambda({region})

  let arn = `arn:aws:lambda:${region}:${account}:function:${name}-${env}-ws-${RouteKey.replace('$', '')}`

  // used later
  let integrationId
  waterfall([

    /**
     * setup the integration
     */
    function createIntegration(callback) {
      setTimeout(function throttle() {
        let uri = `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${arn}/invocations`
        // console.log(api)
        gateway.createIntegration({
          ApiId: api.ApiId,
github lemoncloud-io / lemon-core / src / cores / protocol / protocol-service.ts View on Github external
// const url = new URL(uri);
        const url = URL.parse(uri);
        const payload = this.transformEvent(uri, param);

        //! prepare lambda payload.
        const params: Lambda.Types.InvocationRequest = {
            FunctionName: url.hostname,
            Payload: payload ? $U.json(payload) : '',
            ClientContext: null,
            // InvocationType: 'Event',
        };
        // _log(NS, `> params =`, $U.json(params));

        //! call lambda.
        const region = 'ap-northeast-2';
        const lambda = new AWS.Lambda({ region });
        const response = await lambda
            .invoke(params)
            .promise()
            .catch((e: Error) => {
                _err(NS, `! execute[${param.service || ''}].err =`, typeof e, e);
                return this.doReportError(e, param.context, null, { protocol: uri, param });
            })
            .then((data: Lambda.Types.InvocationResponse) => {
                _log(NS, `! execute[${param.service || ''}].res =`, $U.json(data));
                const payload = data.Payload ? JSON.parse(`${data.Payload}`) : {};
                const statusCode = $U.N(payload.statusCode || data.StatusCode, 200);
                _log(NS, `> Lambda[${params.FunctionName}].StatusCode :=`, statusCode);
                //! safe parse payload.body.
                const body = (() => {
                    try {
                        if (payload.text && typeof payload.text == 'string') return payload.text;
github snowplow / aws-lambda-nodejs-example-project / tasks / deployLambda.js View on Github external
grunt.registerMultiTask('deployLambda', DESC, function () {
      
        var DEFAULTS = {
            endpoint:  'iam.amazonaws.com'
        };
        var credentials = new AWS.SharedIniFileCredentials({profile: 'default'});
        AWS.config.credentials = credentials;
 
        var done = this.async();

        AWS.config.update({region: 'us-east-1'});
        var lambda = new AWS.Lambda({
            apiVersion: '2015-03-31'
        });

        var iam = new AWS.IAM({apiVersion: '2010-05-08'});
        iam.config.endpoint = DEFAULTS.endpoint;
        iam.endpoint = DEFAULTS.endpoint;

        // main
        var subtasks = [];
        subtasks.push(listRoles);
        subtasks.push(createFunction);
        async.series(subtasks, done);

        function listRoles(callback) {
            paramsRole = {}
            iam.listRoles(paramsRole, function(err, data) {
github tensult / aws-automation / set_lambda_function_invocation_count_alarm.js View on Github external
async function setFunctionInvocationAlarms() {
await awsConfigHelper.updateConfig(cliArgs.region);
const lambda = new AWS.Lambda();
const cloudwatch = new AWS.CloudWatch();
while (!isCompleted) {
    try {
        const response = await lambda.listFunctions({
            Marker: nextToken
        }).promise();
        if (response.Functions) {
            for (let i = 0; i < response.Functions.length; i++) {
                const fn = response.Functions[i];
                if (cliArgs.filterName && !fn.FunctionName.match(filterRegex)) {
                    console.log("Skipping function", fn.FunctionName);
                    continue;
                }
                console.log(`Creating Invocation count Alarm for function: ${fn.FunctionName}`);
                await cloudwatch.putMetricAlarm({
                    AlarmName: `${fn.FunctionName}_InvocationCount`,
github DanteInc / js-cloud-native-cookbook / ch2 / replaying-events / lib / replay.js View on Github external
exports.handler = (argv) => {
    console.log('args: %j', argv);

    aws.config.logger = process.stdout;
    aws.config.region = argv.region;

    const s3 = new aws.S3();
    const lambda = new aws.Lambda();

    paginate(s3, argv)
        .flatMap(obj => get(s3, argv, obj))
        .flatMap(event => invoke(lambda, argv, event))
        .collect()
        .each(list => console.log('count:', list.length))
        ;
}
github claudiajs / claudia / src / commands / add-scheduled-event.js View on Github external
const initServices = function () {
			lambda = new aws.Lambda({region: lambdaConfig.region});
			events = new aws.CloudWatchEvents({region: lambdaConfig.region});
		},
		getLambda = () => lambda.getFunctionConfiguration({FunctionName: lambdaConfig.name, Qualifier: options.version}).promise(),
github systemaccounting / mxfactorial / services / graphql-faas / src / graphql / resolvers / Rule.js View on Github external
const AWS = require('aws-sdk')

const lambda = new AWS.Lambda()
const ddb = new AWS.DynamoDB.DocumentClient({ region: process.env.AWS_REGION })

const getRules = async (
  rulesToQuery,
  queryFunc,
  service,
  tableName,
  rangeKey
  ) => {
  let rules = []
  for (ruleSchema of rulesToQuery) {
    let partialList = await queryFunc(
      service,
      tableName,
      rangeKey,
      ruleSchema
github timroesner / WeMart / src / AccountSettings.js View on Github external
getPaymentSources(email){
        var lambda;
        if(process.env.NODE_ENV === 'development'){
            lambda = new AWS.Lambda(require('./db').lambda)
        } else {
          lambda = new AWS.Lambda({
            region: "us-west-1",
            credentials: {
                accessKeyId: process.env.REACT_APP_DB_accessKeyId,
                secretAccessKey: process.env.REACT_APP_DB_secretAccessKey},
        });
        }
        var payLoad = {
            "stripeEmail": email
            };
           
           var params = {
               FunctionName: 'retrieveCustomerSources',
               Payload: JSON.stringify(payLoad)
           
           };
           let self =this
github architect / architect / src / create / aws / create-queue-lambda-deployments / _create-lambda / index.js View on Github external
module.exports = function _create({app, queue, name}, callback) {
  let lambda = new aws.Lambda({region: process.env.AWS_REGION})
  lambda.getFunction({
    FunctionName: name
  },
  function _getFunction(err) {
    if (err && err.name === 'ResourceNotFoundException') {
      print.create('@queues', name)

      let read = _read.bind({}, queue)
      let upload = _upload.bind({}, {app, queue, name})

      waterfall([
        iam,
        read,
        upload,
        map,
      ], callback)
github serverless / serverless / lib / utils / aws.js View on Github external
exports.lambdaGetPolicy = function(awsProfile, awsRegion, functionName) {
  this.configAWS(awsProfile, awsRegion);

  let lambda = new AWS.Lambda();

  let params = {
    FunctionName: functionName.trim(),
  };

  return new BbPromise(function(resolve, reject) {
    lambda.getPolicy(params, function(err, data) {

      if (err) {
        return reject(err);
      }

      return resolve(data);

    });
  });