How to use the @pulumi/aws.serverless function in @pulumi/aws

To help you get started, we’ve selected a few @pulumi/aws 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 pulumi / pulumi-aws / tests / serverless_functions / index.ts View on Github external
// Copyright 2016-2017, Pulumi Corporation.  All rights reserved.

import * as aws from "@pulumi/aws";
import * as other from "./other/index"

// Validate that 'require'd packages are captured correctly.
function getContentType() {
  let mime = require('mime-types');
  return mime.contentType(".js");
}
const testFunc = new aws.serverless.Function("f", {
  policies: [aws.iam.AWSLambdaFullAccess],
  includePaths: ['./Pulumi.yaml'],
}, async (ev, ctx, cb) => {
  var aws = await import('aws-sdk');
  var express = await import('express');
  var os = require('os');
  var slack = require('@slack/client');

  var answer = other.answer;
  console.log(answer);
  getContentType();
});

exports.functionARN = testFunc.lambda.arn;
github pulumi / pulumi-aws / examples / serverless / index.ts View on Github external
(event, context, callback) => {
    console.log("Music table hash key is: " + music.hashKey);
    console.log("Invoked function: " + context.invokedFunctionArn);
    callback(null, {
      statusCode: 200,
      body: hello + "\n\nSucceeed with " + context.getRemainingTimeInMillis() + "ms remaining.\n",
    });
  },
);

// Validate that 'require'd packages are captured correctly.
function getContentType() {
  let mime = require('mime-types');
  return mime.contentType(".js");
}
const testFunc = new aws.serverless.Function("f", {
  policies: [aws.iam.AWSLambdaFullAccess],
  includePaths: ['./Pulumi.yaml'],
  includePackages: ['body-parser'],
}, async (ev, ctx, cb) => {
  var aws = await import('aws-sdk');
  var express = await import('express');
  var os = require('os');
  // TODO[pulumi/pulumi#463] Its reasonable to expect that `./other` would work here, but it currently does not.  For
  // now, validate that the approach that does currently work will serialize the dependencies correctly.
  var answer = require('./bin/other').answer;
  console.log(answer);
  getContentType();
});

exports.functionARN = testFunc.lambda.arn;
github pulumi / pulumi-aws / examples / serverless / index.ts View on Github external
projectionType: "INCLUDE",
    },
    {
      name: "myGSI2",
      hashKey: "NumberOfSongs",
      rangeKey: "Sales",
      nonKeyAttributes: ["Album", "Artist"],
      projectionType: "INCLUDE",
      readCapacity: 2,
      writeCapacity: 2,
    },
  ],
});

let hello = "Hello, world!";
let lambda = new aws.serverless.Function(
  "mylambda",
  { policies: [aws.iam.AWSLambdaFullAccess] },
  (event, context, callback) => {
    console.log("Music table hash key is: " + music.hashKey);
    console.log("Invoked function: " + context.invokedFunctionArn);
    callback(null, {
      statusCode: 200,
      body: hello + "\n\nSucceeed with " + context.getRemainingTimeInMillis() + "ms remaining.\n",
    });
  },
);

// Validate that 'require'd packages are captured correctly.
function getContentType() {
  let mime = require('mime-types');
  return mime.contentType(".js");
github pulumi / pulumi-cloud / aws / function.ts View on Github external
deadLetterConfig: {
                targetArn: getUnhandledErrorTopic().arn,
            },
            memorySize: functionMemorySize,
        };
        if (runLambdaInVPC) {
            const network: Network | undefined = getNetwork();
            // TODO[terraform-providers/terraform-provider-aws#1507]: Updates which cause existing Lambdas to need to
            //     add VPC access will currently fail due to an issue in the Terraform provider.
            options.policies.push(aws.iam.AWSLambdaVPCAccessExecutionRole);
            options.vpcConfig = {
                securityGroupIds: network!.securityGroupIds,
                subnetIds: network!.subnetIds,
            };
        }
        this.lambda = new aws.serverless.Function(name, options, handler, { parent: this }).lambda;

        // And then a log group and subscription filter for that lambda.
        const _ = new aws.cloudwatch.LogSubscriptionFilter(name, {
            logGroup: new aws.cloudwatch.LogGroup(name, {
                name: this.lambda.name.then((n: string | undefined) => n && ("/aws/lambda/" + n)),
                retentionInDays: 1,
            }, { parent: this }),
            destinationArn: getLogDestinationArn(),
            filterPattern: "",
        }, { parent: this });
    }
}
github pulumi / pulumi-cloud / aws / logCollector.ts View on Github external
constructor(name: string, opts?: pulumi.ResourceOptions) {
        super("cloud:logCollector:LogCollector", name, opts);

        const collector = new aws.serverless.Function(
            name,
            { policies: [ aws.iam.AWSLambdaFullAccess ] },
            async (ev: LogsPayload, ctx: aws.serverless.Context, cb: (error: any, result?: {}) => void) => {
                try {
                    const zlib = await import("zlib");
                    const payload = new Buffer(ev.awslogs.data, "base64");
                    const result = zlib.gunzipSync(payload);
                    console.log(result.toString("utf8"));
                    cb(null, {});
                } catch (err) {
                    cb(err);
                }
            },
            { parent: this },
        );
        this.lambda = collector.lambda;
github pulumi / pulumi-cloud / aws / logCollector.ts View on Github external
constructor(name: string, opts?: pulumi.ResourceOptions) {
        super("cloud:logCollector:LogCollector", name, opts);

        const collector = new aws.serverless.Function(
            name,
            { policies: [ aws.iam.AWSLambdaFullAccess ] },
            async (ev: LogsPayload, ctx: aws.serverless.Context, cb: (error: any, result?: {}) => void) => {
                try {
                    const zlib = await import("zlib");
                    const payload = new Buffer(ev.awslogs.data, "base64");
                    const result = zlib.gunzipSync(payload);
                    console.log(result.toString("utf8"));
                    cb(null, {});
                } catch (err) {
                    cb(err);
                }
            },
            { parent: this },
        );
        this.lambda = collector.lambda;
github pulumi / pulumi-aws-serverless / nodejs / aws-serverless / function.ts View on Github external
export function createLambdaFunction(
    name: string, handler: Handler, opts?: ResourceOptions,
    functionOptions?: aws.serverless.FunctionOptions): aws.lambda.Function {

    if (typeof handler === "function") {
        if (!functionOptions) {
            functionOptions  = {
                policies: defaultComputePolicies.slice(),
            };
        }

        const serverlessFunction = new aws.serverless.Function(
            name, functionOptions, handler, opts);

        return serverlessFunction.lambda;
    } else {
        return handler;
    }
}
github pulumi / examples / aws-ts-stepfunctions / index.ts View on Github external
const sfnRolePolicy = new aws.iam.RolePolicy("sfnRolePolicy", {
    role: sfnRole.id,
    policy: {
        Version: "2012-10-17",
        Statement: [{
            Effect: "Allow",
            Action: [
                "lambda:InvokeFunction",
            ],
            Resource: "*",
        }],
    },
});

const helloFunction = new aws.serverless.Function(
    "helloFunction",
    { role: lambdaRole },
    (event, context, callback) => {
        callback(null, "Hello");
    },
);

const worldFunction = new aws.serverless.Function(
  "worldFunction",
  {role: lambdaRole},
  (event, context, callback) => {
    callback(null, `${event} World!`);
  },
);

const stateMachine = new aws.sfn.StateMachine("stateMachine", {
github pulumi / examples / aws-ts-stepfunctions / index.ts View on Github external
"lambda:InvokeFunction",
            ],
            Resource: "*",
        }],
    },
});

const helloFunction = new aws.serverless.Function(
    "helloFunction",
    { role: lambdaRole },
    (event, context, callback) => {
        callback(null, "Hello");
    },
);

const worldFunction = new aws.serverless.Function(
  "worldFunction",
  {role: lambdaRole},
  (event, context, callback) => {
    callback(null, `${event} World!`);
  },
);

const stateMachine = new aws.sfn.StateMachine("stateMachine", {
    roleArn: sfnRole.arn,
    definition: pulumi.all([helloFunction.lambda.arn, worldFunction.lambda.arn])
      .apply(([helloArn, worldArn]) => {
      return JSON.stringify({
        "Comment": "A Hello World example of the Amazon States Language using two AWS Lambda Functions",
        "StartAt": "Hello",
        "States": {
          "Hello": {