<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0"><channel><title>Pulumi Blog: Logging</title><link>https://www.pulumi.com/blog/tag/logging/</link><description>Pulumi blog posts: Logging.</description><language>en-us</language><pubDate>Mon, 02 Dec 2019 00:00:00 +0000</pubDate><item><title>Pulumi Watch: Fast Inner Loop Development for Infrastructure</title><link>https://www.pulumi.com/blog/pulumi-watch-mode-fast-inner-loop-development-for-cloud-infrastructure/</link><pubDate>Mon, 02 Dec 2019 00:00:00 +0000</pubDate><guid>https://www.pulumi.com/blog/pulumi-watch-mode-fast-inner-loop-development-for-cloud-infrastructure/</guid><description>
&lt;img src="https://www.pulumi.com/images/generated/blog/pulumi-watch-mode-fast-inner-loop-development-for-cloud-infrastructure/index.png" /&gt;
&lt;p&gt;A big part of our vision with Pulumi is to bring application developers and infrastructure teams closer together in the cloud. That includes both providing infrastructure teams with better software engineering tools, as well as providing developers with easier access to cloud infrastructure. We are often inspired by looking at great software engineering experiences in other development stacks and applying them to the cloud infrastructure space. Whether it be general-purpose languages and rich IDEs, testing and package management, or components and rich APIs, at Pulumi, we’ve repeatedly applied successful development tools and practices to the challenges of building and scaling modern cloud infrastructure.&lt;/p&gt;
&lt;p&gt;As we look across other areas of successful application development, one of the most critical drivers of creativity and productivity is the &lt;strong&gt;speed of iteration&lt;/strong&gt;. When developers can make a change and see or experience the results nearly instantaneously, they can explore solutions quicker, can take more creative risks (and thus learn more), and can ultimately iterate more quickly toward their desired result. From fast build times as a driving force in the design of the Go language, to the DevTools in Chrome, to Edit-and-Continue in Visual Studio, to the &lt;code&gt;watch&lt;/code&gt; modes on tools like TypeScript, this idea of enabling quick or near-instantaneous feedback as code changes are made is a driving force behind many of the most successful developer experiences across a wide variety of software development environments.&lt;/p&gt;
&lt;h2 id="introducing-pulumi-watch"&gt;Introducing Pulumi Watch&lt;/h2&gt;
&lt;p&gt;In &lt;a href="https://github.com/pulumi/pulumi/blob/master/CHANGELOG.md#150-2019-11-06"&gt;Pulumi 1.5&lt;/a&gt;, we released a preview of a new &lt;code&gt;pulumi watch&lt;/code&gt; command. This command provides a mode for developing cloud infrastructure that speeds up the rate of iteration and allows cloud developers to focus on their code and infrastructure, instead of on the mechanics of their deployments. With &lt;code&gt;pulumi watch&lt;/code&gt;, cloud infrastructure feels like it’s truly at your fingertips.&lt;/p&gt;
&lt;div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"&gt;
&lt;iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/dCp2Nfa2S2Q?rel=0?autoplay=0&amp;amp;controls=1&amp;amp;end=0&amp;amp;loop=0&amp;amp;mute=0&amp;amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;p&gt;The video above shows an example of working with some S3 resources. Every time I hit “save” in my editor, &lt;code&gt;pulumi watch&lt;/code&gt; automatically deploys any changes to my infrastructure. If I add a new &lt;code&gt;BucketObject&lt;/code&gt; resources and hit save, the object appears in S3. If I add a loop around it and hit save, 10 new objects appear and the original object is removed. And if I add an event handler, the 5 Lambda and IAM resources needed are deployed in seconds and are hooked up to the bucket. You don’t have to switch back and forth between an editor and a terminal, and you don’t have to go through heavyweight infrastructure deployment tools like Terraform or wait on slow external services like CloudFormation or CI/CD. Instead, changes appear directly in the cloud within seconds of hitting enter. You can try things out, experiment, learn, and rapidly iterate on your cloud infrastructure.&lt;/p&gt;
&lt;p&gt;This new &lt;code&gt;watch&lt;/code&gt; mode isn’t a replacement for a standard &lt;code&gt;pulumi preview&lt;/code&gt;/&lt;code&gt;pulumi update&lt;/code&gt;. For production infrastructure deployments, it is critical to understand precisely what changes will happen before applying them, to integrate with CI/CD systems, to be able to do targeted updates, and to &lt;a href="https://www.pulumi.com/blog/announcing-crossguard-preview/"&gt;apply policy&lt;/a&gt; to guard the production environment against misconfiguration. But that same level of care isn’t necessarily the right way to approach building new features in a development stack. And it’s in these development environments that &lt;code&gt;pulumi watch&lt;/code&gt; opens up a new experience for infrastructure development. Although they are shorter periods relative to the full life of an infrastructure deployment, they are the majority of the time that creativity and creation is applied to cloud infrastructure, and thus represent a key opportunity to empower developers.&lt;/p&gt;
&lt;p&gt;Not all cloud resources can be deployed or updated in seconds - but many of the most popular modern cloud primitives are built on platforms that enable and encourage quick iteration - and in particular both serverless and Kubernetes. Watch mode can be used during the development of any infrastructure, but can really shine in these areas where the cloud platforms natively support fast iteration.&lt;/p&gt;
&lt;h2 id="kubernetes-infrastructure--applications"&gt;Kubernetes Infrastructure + Applications&lt;/h2&gt;
&lt;p&gt;For Kubernetes, &lt;code&gt;pulumi watch&lt;/code&gt; allows us to deploy changes to our cluster automatically as we author our Kubernetes resources. Change the number of &lt;code&gt;replicas&lt;/code&gt; for our &lt;code&gt;Deployment&lt;/code&gt; and hit save and the new pods scale-out. Add a &lt;code&gt;Service&lt;/code&gt; to expose the deployment and public endpoint is available immediately. This pairs beautifully with the recently released &lt;a href="https://www.pulumi.com/blog/introducing-kx"&gt;Pulumi Kubernetes Extensions (&lt;code&gt;kx&lt;/code&gt;)&lt;/a&gt; library, which allows you to build Kubernetes applications with just a few lines of code - avoiding a lot of the boilerplate that slows down typical Kubernetes development when working with YAML. We can see this combination in action in the video below:&lt;/p&gt;
&lt;div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"&gt;
&lt;iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/X96EMLi8uJY?rel=0?autoplay=0&amp;amp;controls=1&amp;amp;end=0&amp;amp;loop=0&amp;amp;mute=0&amp;amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;p&gt;Both of the previous videos also highlight another interesting element of modern cloud infrastructure development. In both the S3 example and the Kubernetes example, the Pulumi program deployed not just the infrastructure, but also the application code and assets. By authoring and delivering both infrastructure and application code together, we remove another aspect of the silos that separate developers from infrastructure, and in doing so, unlock even faster iteration. This is a pattern that Pulumi enables in a wide variety of unique ways, from Lambdas as lambdas, to build-and-push of Docker images, to deploying assets for static sites.&lt;/p&gt;
&lt;h2 id="from-zero-to-cloud-application-in-90-seconds"&gt;From Zero to Cloud Application in 90 Seconds&lt;/h2&gt;
&lt;p&gt;We can bring these ideas together, and show another example of what’s possible with &lt;code&gt;watch&lt;/code&gt; mode using a serverless application example. As with so many things these days, a tweet inspired this example:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I want a website that does one thing: displays the number of times it&amp;rsquo;s been viewed. What is the shortest number of steps you can think of to get it running in the cloud?&lt;/p&gt;
&lt;p&gt;— Slava Akhmechet (&lt;a href="https://twitter.com/spakhm"&gt;@spakhm)&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Indeed, such simple tasks are often surprisingly complex and cumbersome with today’s infrastructure tools. But with &lt;code&gt;pulumi watch&lt;/code&gt; and the Pulumi Cloud Framework, we can go from nothing to having this application deployed in AWS (or Azure!) in under 90 seconds.&lt;/p&gt;
&lt;div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"&gt;
&lt;iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/FuYwsXLqnTk?rel=0?autoplay=0&amp;amp;controls=1&amp;amp;end=0&amp;amp;loop=0&amp;amp;mute=0&amp;amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;When using &lt;code&gt;pulumi watch&lt;/code&gt;, working with cloud infrastructure &lt;em&gt;feels&lt;/em&gt; so different - it feels malleable, it feels accessible, and it feels like it’s right at your fingertips. By building on the same robust incremental deployment infrastructure as the rest of Pulumi, you get the same access to any cloud, and to a variety of languages and all the other benefits of Pulumi’s modern infrastructure as code tooling. Pulumi watch triggers a deploy on any save - including both of files in the Pulumi program itself, as well as other assets that the Pulumi program may reference like application source code or static assets. Pulumi watch also displays &lt;a href="https://www.pulumi.com/blog/unified-logs-with-pulumi-logs/"&gt;runtime logs&lt;/a&gt; for supported platforms (Lambda, ECS, and Cloudwatch currently, more coming soon), and can be paired with another new feature, &lt;a href="https://www.pulumi.com/blog/query-kubernetes/"&gt;Pulumi Query&lt;/a&gt;, to get customized status about the runtime environment during rapid iteration.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;pulumi watch&lt;/code&gt; command is available in preview now when the &lt;code&gt;PULUMI_EXPERIMENTAL&lt;/code&gt; environment variable is set to &lt;code&gt;true&lt;/code&gt;. We are just getting started - and see many more opportunities to tighten the iteration cycle further, to support more logging capabilities, to integrate more deeply with &lt;code&gt;query&lt;/code&gt;, and to be applied to more modern infrastructure scenarios.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.pulumi.com/docs/get-started/"&gt;Give it a try&lt;/a&gt; today and &lt;a href="https://github.com/pulumi/pulumi/issues/3448"&gt;drop us a note&lt;/a&gt; about where you’d like to see this go for &lt;a href="https://www.pulumi.com/blog/pulumi-2-0-roadmap/"&gt;Pulumi 2.0&lt;/a&gt;!&lt;/p&gt;</description><author>Luke Hoban</author><category>serverless</category><category>kubernetes</category><category>logging</category><category>features</category></item><item><title>AWS CloudWatch made easy with Pulumi Infrastructure-as-Code</title><link>https://www.pulumi.com/blog/aws-cloudwatch-made-easy-with-pulumi-infrastructure-as-code/</link><pubDate>Fri, 14 Jun 2019 00:00:00 +0000</pubDate><guid>https://www.pulumi.com/blog/aws-cloudwatch-made-easy-with-pulumi-infrastructure-as-code/</guid><description>
&lt;img src="https://www.pulumi.com/images/generated/blog/aws-cloudwatch-made-easy-with-pulumi-infrastructure-as-code/index.png" /&gt;
&lt;p&gt;Pulumi Crosswalk for AWS modules can be used to get first class insights
and visualizations directly inside your Pulumi application.&lt;/p&gt;
&lt;p&gt;As cloud applications tend to be long-lived, we think it&amp;rsquo;s vital that it
be possible to get regular insights on the performance of the
application at all times. Using
&lt;a href="https://www.pulumi.com/docs/iac/clouds/aws/guides/"&gt;Crosswalk for AWS&lt;/a&gt; Pulumi applications
allow you to easily define and visualize the appropriate
&lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/working_with_metrics.html"&gt;metrics&lt;/a&gt;
that show the health of your services, create
&lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html"&gt;alarms&lt;/a&gt;
to let you know when something is wrong, and easily create
&lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html"&gt;dashboards&lt;/a&gt;
to get live visualization of what is happening in the cloud. Because
this is vital to the health of the application, we think this should be
something built in from the start, and not something added after the
fact as an out of band artifact.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s see what that means in practice! I&amp;rsquo;m going to use a recent
hackathon project I created where I built a &lt;a href="https://api.slack.com/bot-users"&gt;Slack bot&lt;/a&gt; to notify me about all the
&lt;code&gt;@mentions&lt;/code&gt; I&amp;rsquo;d received. Using this, I&amp;rsquo;d have a place I could go back
to to look at, to find messages I knew had come in, but maybe I wanted
to take a second glance at. The bot just sends me messages in a private
channel we share like so:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/aws-cloudwatch-made-easy-with-pulumi-infrastructure-as-code/mention-bot.png" alt="Mention Bot 9000"&gt;&lt;/p&gt;
&lt;p&gt;I intend to add more functionality to this bot over time to help me out.
If you&amp;rsquo;d like to create something similar, the code and instructions are
&lt;a href="https://github.com/pulumi/examples/tree/master/aws-ts-slackbot"&gt;here&lt;/a&gt;.
The bot works by hearing about incoming events (pushed to
it from Slack&amp;rsquo;s servers), looking for mentions of my name, then pushing
requests back to Slack&amp;rsquo;s server to update our private channel.&lt;/p&gt;
&lt;p&gt;Now the bot I wrote has to do something interesting due to restrictions
in the Slack messaging system. Slack will only give you a few seconds to
deal with a message they send you. If you don&amp;rsquo;t complete the request in
a timely fashion then they&amp;rsquo;ll assume something has gone wrong, and
they&amp;rsquo;ll resend. This will happen a few times before they just give up.
This means that we don&amp;rsquo;t really want to try to process a message, and
then also make an outgoing network call to Slack all in the same
request. That outgoing call could take far too long, causing Slack to
think there was a problem. So, instead, we simply receive the request,
and push it right away to an &lt;a href="https://aws.amazon.com/sns/"&gt;SNS&lt;/a&gt; topic.
We can then process that topic message later with another Lambda.&lt;/p&gt;
&lt;p&gt;The skeleton of the code basically looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Location to store the incoming slack messages to.
const messageTopic = new aws.sns.Topic(&amp;quot;messages&amp;quot;);
// Create an API endpoint that slack will use to push events to us with.
const endpoint = new awsx.apigateway.API(&amp;quot;mentionbot&amp;quot;, {
routes: [{
path: &amp;quot;/events&amp;quot;,
method: &amp;quot;POST&amp;quot;,
eventHandler: async (event) =&amp;gt; {
// process the different types of messages. Push normal messages to 'messageTopic'
// ...
// Return success quickly so that Slack doesn't just immediately resend this message to us.
return { statusCode: 200, body: &amp;quot;&amp;quot; };
},
}],
});
// Hook up a lambda that will then process the topic when possible.
const subscription = messageTopic.onEvent(&amp;quot;processTopicMessage&amp;quot;, async ev =&amp;gt; {
// process the messages in here. Look for mentions, then notify slack to post a message in
// right channel if we find one.
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Overall, this is a very simple app. But how do we know if the app is
actually doing well? What if something starts to go wrong and the
&lt;code&gt;endpoint&lt;/code&gt; is no longer responding in a timely fashion. How would we
find out? It turns out to be pretty simple to add this functionality
here! Let&amp;rsquo;s see how that would look.&lt;/p&gt;
&lt;p&gt;First, we want to be profiling the &lt;a href="https://aws.amazon.com/lambda/"&gt;Lambda Functions&lt;/a&gt; that were created by those
two resources. That&amp;rsquo;s very simple to do:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const endpointFunc = endpoint.getFunction(&amp;quot;/events&amp;quot;);
const topicFunc = subscription.func;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, we want to get information about how long these functions are
taking. With Pulumi&amp;rsquo;s
&lt;a href="https://www.pulumi.com/docs/iac/clouds/aws/guides/"&gt;Crosswalk&lt;/a&gt; APIs it&amp;rsquo;s simple
to get at this information. Inside all the main &amp;ldquo;Crosswalk for AWS&amp;rdquo;
modules are exposed
&lt;a href="https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/awsx/classic/cloudwatch/#Metric"&gt;Metrics&lt;/a&gt;
for almost anything you might ever need. In this case, we want to know
how long those Functions are taking so we can get that information as
follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const endpointFuncDuration = awsx.lambda.metrics.duration({ function: endpointFunc });
const topicProcessDuration = awsx.lambda.metrics.duration({ function: topicFunc });
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Metrics are very customizable. But for now we&amp;rsquo;ll just use the defaults
returned for those functions by AWS. Now that we have the metrics, it&amp;rsquo;s
simple to create an CloudWatch alarm that will alert us when things take
too long:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Notify us if takes us longer than 5 seconds to process a Slack message. But only notify if this
// happened at least once every 5 minutes in a 15 minute period. We're ok with the occasional
// random network hiccup causing delays.
const alarm = endpointFuncDuration.withUnit(&amp;quot;Seconds&amp;quot;)
.withPeriod(300)
.createAlarm(&amp;quot;TooLong&amp;quot;, {
threshold: 5,
evaluationPeriods: 3,
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Finally, we can use both those metrics &lt;em&gt;and&lt;/em&gt; the alarm we just created
to make a great looking dashboard that we can use to get an overall view
of the health of this app:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const dashboard = new awsx.cloudwatch.Dashboard(&amp;quot;mentionbot&amp;quot;, {
widgets: [
new awsx.cloudwatch.LineGraphMetricWidget({
width: 12,
title: &amp;quot;Receiving duration&amp;quot;,
metrics: [ endpointFuncDuration.with({ extendedStatistic: 99, label: &amp;quot;Duration p99&amp;quot; }) ],
annotations: new awsx.cloudwatch.HorizontalAnnotation(alarm),
}),
new awsx.cloudwatch.LineGraphMetricWidget({
width: 12,
title: &amp;quot;Processing duration&amp;quot;,
metrics: [ topicProcessDuration.with({ extendedStatistic: 99, label: &amp;quot;Duration p99&amp;quot; }) ],
}),
],
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;a href="https://github.com/pulumi/pulumi-awsx/tree/master/awsx-classic/cloudwatch#dashboards"&gt;Crosswalk for AWS API for dashboards&lt;/a&gt;
gives a lot of options for building up a dashboard programmatically.
There are a wealth of Widgets and Annotations to expose the full power
of Cloudwatch&amp;rsquo;s dashboards to your app in a simple to use manner.&lt;/p&gt;
&lt;p&gt;With the above Dashboard code we get this useful chart:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/aws-cloudwatch-made-easy-with-pulumi-infrastructure-as-code/dashboard.png" alt="CloudWatch Dashboard using Pulumi"&gt;&lt;/p&gt;
&lt;p&gt;We can see that things look healthy, and the chart shows us both the
information about our p99 latencies, as well as the threshold point that
would cause our alarm to trigger.&lt;/p&gt;
&lt;p&gt;With these facilities I now have an app that does what I need, but also
directly exposes mechanisms to track and get insights to its health.
What&amp;rsquo;s great is that if I now change my app (for example, in a way that
causes new Lambda Functions to be created), I don&amp;rsquo;t need to do anything
to keep these alarms and dashboards working. Because they&amp;rsquo;re directly
referencing the real Cloud resources they will be kept up to date
automatically as my app grows and changes over time. That&amp;rsquo;s really
powerful, and much simpler than having to manage all these different
parts independently!&lt;/p&gt;
&lt;p&gt;We hope these new Crosswalk for AWS APIs will be just as useful for you!
For more information on Pulumi Crosswalk for AWS checkout other related
content:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.pulumi.com/blog/introducing-pulumi-crosswalk-for-aws-the-easiest-way-to-aws/"&gt;Pulumi Crosswalk for AWS Announcement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.pulumi.com/blog/mapbox-iot-as-code-with-pulumi-crosswalk-for-aws/"&gt;Mapbox IOT-as-Code with Pulumi Crosswalk for AWS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.pulumi.com/docs/iac/clouds/aws/guides/"&gt;Pulumi Crosswalk for AWS Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</description><author>Cyrus Najmabadi</author><category>aws</category><category>logging</category></item><item><title>Unified Logs with pulumi logs</title><link>https://www.pulumi.com/blog/unified-logs-with-pulumi-logs/</link><pubDate>Tue, 02 Apr 2019 00:00:00 +0000</pubDate><guid>https://www.pulumi.com/blog/unified-logs-with-pulumi-logs/</guid><description>
&lt;img src="https://www.pulumi.com/images/generated/blog/unified-logs-with-pulumi-logs/index.png" /&gt;
&lt;p&gt;Pulumi makes developing and deploying
&lt;a href="https://www.pulumi.com/blog/easy-serverless-apps-and-infrastructure-real-events-real-code/"&gt;rich serverless and container-based applications&lt;/a&gt;
a breeze. But how do you monitor and observe those applications while
they are being developed and once they are deployed? There are many
great answers: from the built-in capabilities of the underlying cloud
services (Lambda, ECS, Kubernetes, and more), to great 3rd party
solutions like &lt;a href="https://github.com/pulumi/pulumi-iopipe"&gt;IOpipe&lt;/a&gt; and
&lt;a href="https://github.com/pulumi/pulumi-epsagon"&gt;Epsagon&lt;/a&gt; which
&lt;a href="https://www.pulumi.com/blog/pulumi-and-epsagon-define-deploy-and-monitor-serverless-applications/"&gt;we highlighted recently&lt;/a&gt;
on this blog.&lt;/p&gt;
&lt;p&gt;The Pulumi CLI provides another way to do logging, without requiring the
additional setup of these existing solutions and seamlessly integrated
into your Pulumi development workflow. The &lt;code&gt;pulumi logs&lt;/code&gt; command
provides a great first place to start for understanding your Pulumi
application&amp;rsquo;s behavior. Especially during development, this command
provides direct insight into the behavior of your application, bringing
together logs across all of the different forms of compute you are using -
from code running in serverless functions to containers to VMs.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s take a quick look at &lt;code&gt;pulumi logs&lt;/code&gt; and some of the ways it can be
used as part of the inner loop of your Pulumi development.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Note: Currently &lt;code&gt;pulumi logs&lt;/code&gt; supports only logs for applications
running in AWS. In the near future it will be expanded to Kubernetes,
Azure, GCP and additional cloud platforms.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="logging-for-inner-loop-development"&gt;Logging for Inner-Loop Development&lt;/h2&gt;
&lt;p&gt;When developing locally, it is common to use logging as an interactive
part of the development process. With &lt;code&gt;pulumi logs&lt;/code&gt;, we can bring some
of these same approaches into the inner loop of the development process
even for applications being actively developed/deployed in the cloud.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s take a simple example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-typescript" data-lang="typescript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kr"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="kr"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;aws&lt;/span&gt; &lt;span class="kr"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;@pulumi/aws&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kr"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bucket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;aws&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Bucket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;mybucket&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;bucket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onObjectCreated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;newObject&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kr"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bucketName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bucket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can deploy this app, copy an object into the newly provisioned
bucket, and then see the logs with the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ pulumi up --skip-preview
 
$ aws s3 cp somefile.txt s3://$(pulumi stack output bucketName)
 
$ pulumi logs -f
Collecting logs for stack dev since
 
 2019-03-28T21:10:05.667-07:00[ newObject] {&amp;quot;Records&amp;quot;:[{&amp;quot;eventVersion&amp;quot;:&amp;quot;2.1&amp;quot;,&amp;quot;eventSource&amp;quot;:&amp;quot;aws:s3&amp;quot;,&amp;quot;awsRegion&amp;quot;:&amp;quot;us-west-2&amp;quot;,&amp;quot;eventTime&amp;quot;:&amp;quot;2019-03-29T04:10:05.318Z&amp;quot;,&amp;quot;eventName&amp;quot;:&amp;quot;ObjectCreated:Put&amp;quot;,&amp;quot;userIdentity&amp;quot;:{&amp;quot;principalId&amp;quot;:&amp;quot;AWS:AIDAIB2I7NPKMQ2QAKXZ6&amp;quot;},&amp;quot;requestParameters&amp;quot;:{&amp;quot;sourceIPAddress&amp;quot;:&amp;quot;24.35.94.249&amp;quot;},&amp;quot;responseElements&amp;quot;:{&amp;quot;x-amz-request-id&amp;quot;:&amp;quot;F2D7DF26693AEFEE&amp;quot;,&amp;quot;x-amz-id-2&amp;quot;:&amp;quot;o2leqNNwCVXTI8jfvUGk5KE7w6CiKsJYP/Q4nT0fHqZPrqwaVlSP0lNhspv5NiLAAwutCzJwlLc=&amp;quot;},&amp;quot;s3&amp;quot;:{&amp;quot;s3SchemaVersion&amp;quot;:&amp;quot;1.0&amp;quot;,&amp;quot;configurationId&amp;quot;:&amp;quot;tf-s3-lambda-20190328222809603300000002&amp;quot;,&amp;quot;bucket&amp;quot;:{&amp;quot;name&amp;quot;:&amp;quot;mybucket-97f10e0&amp;quot;,&amp;quot;ownerIdentity&amp;quot;:{&amp;quot;principalId&amp;quot;:&amp;quot;A3FZDZNSWOKQHV&amp;quot;},&amp;quot;arn&amp;quot;:&amp;quot;arn:aws:s3:::mybucket-97f10e0&amp;quot;},&amp;quot;object&amp;quot;:{&amp;quot;key&amp;quot;:&amp;quot;out.txt&amp;quot;,&amp;quot;size&amp;quot;:36000,&amp;quot;eTag&amp;quot;:&amp;quot;818ac0cf0273f7e40e673d9892405e31&amp;quot;,&amp;quot;sequencer&amp;quot;:&amp;quot;005C9D9A9D311D5C11&amp;quot;}}}]}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I can use this to quickly see what kind of values I get back on an S3
Bucket Object event, using live data running in the cloud. But I can do
this whole thing in just a couple of seconds - from deployment to logs.
This lets me iterate on my application live in the cloud with ease.&lt;/p&gt;
&lt;p&gt;If there are errors in my code, I find out about them immediately:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-typescript" data-lang="typescript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;bucket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onObjectCreated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;newObject&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;oops&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Results in:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ pulumi logs --since 1m
Collecting logs for stack dev since 2019-03-28T20:17:28.000-07:00.
 
 2019-03-28T21:17:01.269-07:00[ newObject] {&amp;quot;errorMessage&amp;quot;:&amp;quot;oops&amp;quot;,&amp;quot;errorType&amp;quot;:&amp;quot;Error&amp;quot;,&amp;quot;stackTrace&amp;quot;:[&amp;quot;/var/task/__index.js:26:11&amp;quot;,&amp;quot;Generator.next (&amp;lt;anonymous&amp;gt;)&amp;quot;,&amp;quot;/var/task/__index.js:12:71&amp;quot;,&amp;quot;new Promise (&amp;lt;anonymous&amp;gt;)&amp;quot;,&amp;quot;Object.&amp;lt;anonymous&amp;gt; (/var/task/__index.js:8:12)&amp;quot;,&amp;quot;Object.__f1 [as __awaiter] (/var/task/__index.js:17:34)&amp;quot;,&amp;quot;/var/task/__index.js:24:21&amp;quot;,&amp;quot;__f0 (/var/task/__index.js:30:34)&amp;quot;]}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="aggregating-logs"&gt;Aggregating Logs&lt;/h2&gt;
&lt;p&gt;As applications grow to span multiple forms of compute &amp;ndash; such as micro
services, lambdas, containers, and VMs &amp;ndash; it becomes important to be
able to correlate logs across services.&lt;/p&gt;
&lt;p&gt;One great example of this is the &lt;a href="https://github.com/pulumi/examples/tree/master/aws-ts-thumbnailer"&gt;video thumbnailer&lt;/a&gt;
example which implements this simple architecture involving two buckets,
a lambda event, and a long-running Fargate container task.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/unified-logs-with-pulumi-logs/unnamed.png" alt="unnamed"&gt;&lt;/p&gt;
&lt;p&gt;The Pulumi program deploys several components, using different types of
cloud resources. But using &lt;code&gt;Pulumi logs&lt;/code&gt; we can see all logs in a
single, unified view.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/unified-logs-with-pulumi-logs/terminal-logs.png" alt="terminal-logs"&gt;&lt;/p&gt;
&lt;p&gt;From the image above, you can see the &lt;code&gt;onNewVideo&lt;/code&gt; Lambda function, then
triggering the &lt;code&gt;ffmpegThumbTask&lt;/code&gt; Fargate container, and then copying a
file back into S3 triggering the &lt;code&gt;onNewThumbtail&lt;/code&gt; Lambda function. So
you don&amp;rsquo;t need to jump around between different systems for viewing
logs, you can get a consistent view of what&amp;rsquo;s going on in your cloud
application!&lt;/p&gt;
&lt;p&gt;Underneath the hood, these logs live in different and uncorrelated
CloudWatch LogGroups, spread across an AWS account. But with
&lt;code&gt;pulumi logs&lt;/code&gt; we can get the application-centric view we need to
understand the overall behavior of our application architecture.&lt;/p&gt;
&lt;h2 id="controlling-log-rendering"&gt;Controlling Log Rendering&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;pulumi logs&lt;/code&gt; command supports a few options for controlling what
gets logged.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;--since&lt;/code&gt; flag retrieves logs only since a given relative or
absolute time. For example, &lt;code&gt;pulumi logs --since 1m&lt;/code&gt; will get logs just
since 1 minute ago - useful for limiting logs to only what&amp;rsquo;s happened
very recently - especially during inner-loop development. And to get
logs since a specific point in time (such as the timestamp of a known
event from a previous execution of &lt;code&gt;pulumi logs&lt;/code&gt;) you can use
&lt;code&gt;pulumi logs --since 2019-03-28T21:17:01.269-07:00&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A couple of the examples above used the &lt;code&gt;--follow&lt;/code&gt; flag to follow the
log output until cancelled. This is useful when waiting for log output
to come in during debugging.&lt;/p&gt;
&lt;p&gt;And for applications with many resources, it is often important to scope
results down to one or more specific resources, which can be done with
the &lt;code&gt;--resource&lt;/code&gt; flag. For example, logs for just the Fargate task above
could be retrieved with &lt;code&gt;pulumi logs --resource ffmpegThumbTask&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="working-seamlessly-with-your-cloud-provider"&gt;Working Seamlessly with Your Cloud Provider&lt;/h2&gt;
&lt;p&gt;Like many other Pulumi features, &lt;code&gt;pulumi logs&lt;/code&gt; works by building on top
of the great building blocks provided by the underlying cloud provider
services. Instead of adding new runtime logging infrastructure to your
application, &lt;code&gt;pulumi logs&lt;/code&gt; lets you easily extract out logs directly
from your existing infrastructure. But because Pulumi understands the
natural application scope for what resources are part of a single
application, it can bring together the logs from all of those resources
into one place, instead of having to think about individual resources.&lt;/p&gt;
&lt;p&gt;Behind the scenes, &lt;code&gt;pulumi logs&lt;/code&gt; makes the same calls to CloudWatch Logs
or other backend log providers that you would make yourself via the
&lt;code&gt;aws&lt;/code&gt; CLI or AWS Console. But you don&amp;rsquo;t have to think about the physical
identities of the cloud resources themselves - Pulumi takes care of
finding the resources with supported logs, collecting those logs based
on the requested filters, and then presenting them in unified logical
view.&lt;/p&gt;
&lt;h2 id="whats-next"&gt;What&amp;rsquo;s Next?&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ve seen Pulumi users working with Lambda, ECS and other AWS compute
offerings become heavy users of &lt;code&gt;pulumi logs&lt;/code&gt; during development. But
supporting a broad set of cloud providers is key to our mission at
Pulumi - so we really want to bring these benefits to &lt;em&gt;all&lt;/em&gt; Pulumi
users. We&amp;rsquo;ll be expanding &lt;code&gt;pulumi logs&lt;/code&gt; to Kubernetes, Azure and GCP in
the near future - with easy support for plugging in other cloud
providers and cloud resources as sources for log data.&lt;/p&gt;
&lt;p&gt;Even better, because Pulumi allows you to work with multiple cloud
providers at once - like AWS and Kubernetes, or GCP and Azure, or even
two different AWS regions - &lt;code&gt;pulumi logs&lt;/code&gt; will be able to aggregate logs
across multiple cloud providers and offer a seamless application-centric
view of your logs.&lt;/p&gt;
&lt;p&gt;Users of the Pulumi Service at &lt;a href="https://app.pulumi.com/signin"&gt;app.pulumi.com&lt;/a&gt; also would love
to have access to these logs at the click of a button - and this is
something we&amp;rsquo;re also excited to enable in the near future.&lt;/p&gt;
&lt;p&gt;You can take &lt;code&gt;pulumi&lt;/code&gt; for a spin today by checking out the
&lt;a href="https://www.pulumi.com/docs/get-started/"&gt;Getting Started Guide&lt;/a&gt; guide or some of the
&lt;a href="https://github.com/pulumi/examples"&gt;Pulumi Examples&lt;/a&gt; on GitHub. Then join us in the
&lt;a href="https://slack.pulumi.com"&gt;Pulumi Community Slack&lt;/a&gt; to chat about where
you want to see us go (and where you&amp;rsquo;d like to help out!) with
&lt;code&gt;pulumi logs&lt;/code&gt; and other features of the Pulumi open source project in
the coming weeks and months.&lt;/p&gt;</description><author>Luke Hoban</author><category>aws</category><category>features</category><category>logging</category></item></channel></rss>