Integrating IOpipe into your Pulumi projects

Mx Kas Perch
IOpipe Blog
Published in
3 min readOct 17, 2018

--

If you haven’t tried it yet, Pulumi is a really great framework for spinning up projects that include not just Lambdas, but just about any AWS service! Their TypeScript demo for AWS Lambda even includes spinning up a dynamoDB instance. It’s a really interesting framework for building large AWS stacks.

And luckily for us, they’ve implemented IOpipe to run in Pulumi with just a few steps! We’ll start from the beginning, for those new to Pulumi.

Step 1: Install Pulumi & Configure AWS

Use their quickstart guide to install the cli, then make sure you have everything you need to work with AWS.

Step 2: Create your Pulumi project

In your command line, run the following:

pulumi new aws-javascript --dir pulumi-iopipe

This will ask a few questions to help create your project directory, including a pulumi.yaml file, an index.js file, and a package.json file.

Step 3: Install Dependencies

To make sure you have everything you need, run

npm i --save @pulumi/pulumi @pulumi/aws @pulumi/aws-serverless @pulumi/iopipe

in your command line in the directory Pulumi created for your project.

Step 4: Configure IOpipe token

You’ll need to tell Pulumi what your access token for IOpipe is (if you forgot or can’t find it, it’s on the install page when you’re logged in. To do this, run the following in the CLI:

pulumi config set --secret iopipe:token <your token here>

Step 5: Write some code!

In your index.js file, place the following:

const pulumi = require("@pulumi/pulumi");
const aws = require("@pulumi/aws");
const serverless = require("@pulumi/aws-serverless");
// Load the Pulumi IO| integration package
require("@pulumi/iopipe")(pulumi);
// Create a bucket and a function to log new object uploads
const bucket = new aws.s3.Bucket("my-bucket");
serverless.bucket.onPut("onNewObject", bucket, async (ev, ctx) => {
ctx.iopipe.label('NewS3Object')
console.log(ev)
});
exports.bucketName = bucket.bucket;

Step 6: Deploy

To deploy, in your project folder, run

pulumi update

And it should spin up everything for you in just a few seconds (give or take with WiFi speed, of course!)

Stage 7: Test

Log into the AWS Dashboard and go to the Lambda dashboard:

Look for your new function, and click on its name (hint: it should have onNewObject-put-bucket in it). There should be a ‘Test’ button there, go ahead and click it to run this function:

It should run successfully and you’ll see this box appear:

Step 8: View your IOpipe data

Head over to the IOpipe dashboard and you should see a function link for your new function, click it to see that function’s invocation:

At the bottom of the function page, you’ll see our invocation — it even has the label we gave it in our example code:

And that’s it! Getting started with Pulumi and IOpipe is incredibly easy, and gives you a large amount of visibility into the AWS Lambda function you run using the Pulumi framework.

Want to learn more? You can sign up for Pulumi and try our 21-day free trial of IOpipe! You can also chat with us in either the IOpipe community slack or the Pulumi community slack.

--

--