<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0"><channel><title>Pulumi Blog: Aiven</title><link>https://www.pulumi.com/blog/tag/aiven/</link><description>Pulumi blog posts: Aiven.</description><language>en-us</language><pubDate>Thu, 25 Feb 2021 00:00:00 +0000</pubDate><item><title>Zero Downtime InfluxDB Migration with Pulumi and Aiven</title><link>https://www.pulumi.com/blog/pulumi-with-aiven-for-influxdb/</link><pubDate>Thu, 25 Feb 2021 00:00:00 +0000</pubDate><guid>https://www.pulumi.com/blog/pulumi-with-aiven-for-influxdb/</guid><description>
&lt;img src="https://www.pulumi.com/images/generated/blog/pulumi-with-aiven-for-influxdb/index.png" /&gt;
&lt;p&gt;In this article, I’ll show how Pulumi can be used with Aiven’s services to create infrastructure that can be migrated from cloud to cloud with no downtime.&lt;/p&gt;
&lt;p&gt;This tutorial will use Python, Pulumi, Grafana, and an AWS Lambda function to simulate recording temperature data in an InfluxDB database.&lt;/p&gt;
&lt;div class="note note-info"&gt;
&lt;div class="icon-and-line"&gt;
&lt;svg xmlns="http://www.w3.org/2000/svg" class="ph-icon ph-icon--fill" fill="currentColor" aria-hidden="true" focusable="false"&gt;&lt;use href="https://www.pulumi.com/icons/sprite.4a9ac1016b9d8a688a5e7e867f96bdf80115a0739af8c688ba04791e15f64461.svg#p-info-fill"/&gt;&lt;/svg&gt;
&lt;div class="line"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="content"&gt;Register for Multicloud OSS Database Deployments With Zero Downtime - Pulumi and Aiven and learn how to build robust, multi-cloud applications using the language, open source database, and cloud of your choice.&lt;/div&gt;
&lt;/div&gt;
&lt;h2 id="a-quick-introduction-to-pulumi-aiven-and-influxdb"&gt;A quick introduction to Pulumi, Aiven, and InfluxDB&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://www.pulumi.com/"&gt;Pulumi&lt;/a&gt; enables you to create, deploy, and manage infrastructure on any cloud using your favorite languages. Aiven augments this language agnosticism by giving developers and operators the ability to be cloud-agnostic for a variety of popular databases such as MySQL, PostgreSQL, Cassandra, Redis, and more.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://aiven.io/"&gt;Aiven&lt;/a&gt; offers a range of fully-managed open-source cloud database services. By using Aiven, you can accelerate application development on the open source data infrastructure and quickly deploy to public clouds (including AWS, GCP, and Azure).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/influxdata/influxdb"&gt;InfluxDB&lt;/a&gt; is one of the most popular open source time-series databases for storing metrics and events. InfluxDB also has a number of client libraries in a &lt;a href="https://docs.influxdata.com/influxdb/v1.8/tools/api_client_libraries/"&gt;variety&lt;/a&gt; of languages, including Python. Aiven makes this database available as a fully managed, single-tenant service in a variety of resource sizes.&lt;/p&gt;
&lt;p&gt;I want to demonstrate how to migrate your services using Pulumi from one cloud to another with absolutely zero downtime in this tutorial. Data keeps streaming in the entire time, which you can visualize in &lt;a href="https://grafana.com"&gt;Grafana&lt;/a&gt;. This gives you an added security factor in fault situations and great flexibility in terms of migrating services for any reason.&lt;/p&gt;
&lt;h2 id="demo-outline"&gt;Demo outline&lt;/h2&gt;
&lt;p&gt;This demo will deploy the following infrastructure:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Grafana instance on Aiven (hosted on GCP)&lt;/li&gt;
&lt;li&gt;InfluxDB database instance on Aiven (hosted on GCP)&lt;/li&gt;
&lt;li&gt;Service integration between InfluxDB and Grafana&lt;/li&gt;
&lt;li&gt;AWS Lambda Layer for the Python &lt;a href="https://pypi.org/project/requests/"&gt;requests&lt;/a&gt; library&lt;/li&gt;
&lt;li&gt;AWS Lambda function and associated role&lt;/li&gt;
&lt;li&gt;AWS EventBridge trigger to execute the Lambda function every 60s&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We will then migrate our services from a hybrid cloud (GCP + AWS) to a single cloud (AWS alone) with a single command and experience no downtime.&lt;/p&gt;
&lt;p&gt;The lambda function code (located in the file lambda_code.py) is very basic. It only writes a randomly generated value (outside_temp) to InfluxDB using the InfluxDB Python Client library.&lt;/p&gt;
&lt;h3 id="requirements"&gt;Requirements&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Accounts for AWS, Pulumi &amp;amp; Aiven&lt;/li&gt;
&lt;li&gt;Python 3.7+&lt;/li&gt;
&lt;li&gt;AWS CLI 2.0+&lt;/li&gt;
&lt;li&gt;Pulumi 2.16+&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="cost-estimate"&gt;Cost estimate&lt;/h3&gt;
&lt;p&gt;This tutorial is about as cheap as they come; all you need is some time to perform all the steps.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$0 for AWS Lambda charges&lt;/li&gt;
&lt;li&gt;&lt;a href="https://app.pulumi.com/site/trial"&gt;Free Pulumi trial account&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Free credits for new Aiven users (less than $1/hr for existing customers)&lt;/li&gt;
&lt;li&gt;20-minute time estimate&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="set-up-the-environment"&gt;Set up the environment&lt;/h2&gt;
&lt;p&gt;Your first step is to install Python. Follow the &lt;a href="https://www.pulumi.com/docs/iac/get-started/aws/"&gt;directions on this page&lt;/a&gt; to install Python on your local system.&lt;/p&gt;
&lt;p&gt;Next, get the Aiven examples by cloning this &lt;a href="https://github.com/aiven/aiven-examples"&gt;repo&lt;/a&gt; to your local machine.&lt;/p&gt;
&lt;p&gt;Run the setup script in the repo to activate the Python virtual environment and install the required dependencies:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ &lt;span class="nb"&gt;cd&lt;/span&gt; aiven-examples/pulumi/influxdb_grafana_lambda
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ chmod +x setup.sh &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; ./setup.sh
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="set-your-aiven-api-token-using-the-pulumi-cli"&gt;Set your Aiven API token using the Pulumi CLI:&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi config &lt;span class="nb"&gt;set&lt;/span&gt; aiven:apiToken XXXXXXXXXXXXXXXXXXXX --secret
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="note note-info"&gt;
&lt;div class="icon-and-line"&gt;
&lt;svg xmlns="http://www.w3.org/2000/svg" class="ph-icon ph-icon--fill" fill="currentColor" aria-hidden="true" focusable="false"&gt;&lt;use href="https://www.pulumi.com/icons/sprite.4a9ac1016b9d8a688a5e7e867f96bdf80115a0739af8c688ba04791e15f64461.svg#p-info-fill"/&gt;&lt;/svg&gt;
&lt;div class="line"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="content"&gt;Note that you can &lt;a href="https://console.aiven.io/profile/auth"&gt;generate an API Token&lt;/a&gt; on your profile page.&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id="install-the-aiven-and-aws-plugins-for-pulumi"&gt;Install the Aiven and AWS plugins for Pulumi:&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi plugin install resource aws 3.22.0
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi plugin install resource aiven 3.3.2
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;To find out the current version numbers, go to
&lt;a href="https://github.com/pulumi/pulumi-aws/releases"&gt;Pulumi changelog&lt;/a&gt; or the &lt;a href="https://github.com/pulumi/pulumi-aiven/releases"&gt;Aiven changelog&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Set your preferred cloud regions and Aiven project name (these defaults are used in the setup script):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi config &lt;span class="nb"&gt;set&lt;/span&gt; aws:region &amp;lt;desired AWS region&amp;gt; Example: us-west-2
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi config &lt;span class="nb"&gt;set&lt;/span&gt; aiven_cloud_region &amp;lt;desired cloud - region&amp;gt; Example: google-us-central1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi config &lt;span class="nb"&gt;set&lt;/span&gt; aiven_project &amp;lt;Aiven project&amp;gt; Example: sa-demo
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Example: google-us-central1&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi config &lt;span class="nb"&gt;set&lt;/span&gt; aiven_project &amp;lt;Aiven project&amp;gt; Example: sa-demo
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;Supported regions/clouds for each service are listed on the &lt;a href="https://aiven.io/pricing"&gt;pricing page&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Project names are on the top left corner of the Aiven console.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/pulumi-with-aiven-for-influxdb/aiven_console.png" alt="Aiven console"&gt;&lt;/p&gt;
&lt;h3 id="use-pulumi-to-create-two-services-in-aiven"&gt;Use Pulumi to create two services in Aiven&lt;/h3&gt;
&lt;p&gt;Now that you’re all set up, it’s time to create the services in the Aiven environment by using Pulumi. Issue the following commands to deploy the stack:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi up
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Select &lt;strong&gt;Yes&lt;/strong&gt; to confirm the deployment.&lt;/p&gt;
&lt;p&gt;After about 5 minutes or so, you should see that all of the resources have been created. The URLs and username/password combinations listed are needed to access the services. The &lt;code&gt;influxdb_uri&lt;/code&gt; shown here is also added as an environment variable in the Lambda function so that the Python client can connect to InfluxDB.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/pulumi-with-aiven-for-influxdb/pulumi_outputs.png" alt="Pulumi outputs"&gt;&lt;/p&gt;
&lt;h3 id="aiven-console"&gt;Aiven console&lt;/h3&gt;
&lt;p&gt;To see the new services, log into the &lt;a href="https://console.aiven.io/"&gt;Aiven console&lt;/a&gt;. The resources pulumi-influxdb and pulumi-grafana are displayed.&lt;/p&gt;
&lt;p&gt;&lt;img src="current_services.png" alt="Current services"&gt;&lt;/p&gt;
&lt;h3 id="aws-console"&gt;AWS console&lt;/h3&gt;
&lt;p&gt;In the AWS console, the lambda function has also been created and will be executed by EventBridge every 60 seconds.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/pulumi-with-aiven-for-influxdb/aws_console.png" alt="AWS Console"&gt;&lt;/p&gt;
&lt;h3 id="grafana"&gt;Grafana&lt;/h3&gt;
&lt;p&gt;Now things get exciting: you can see the real-world (for certain values of real, in any case) data streaming in by opening Grafana.&lt;/p&gt;
&lt;p&gt;Open up the &lt;code&gt;grafana_uri&lt;/code&gt; (shown in the console output) and log in with the provided username and password.&lt;/p&gt;
&lt;p&gt;Click on the Explore panel and search for the outside_temp value written by the lambda function every minute (triggered by EventBridge).&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/pulumi-with-aiven-for-influxdb/grafana.png" alt="Grafana"&gt;&lt;/p&gt;
&lt;h2 id="migrate-your-service-from-one-region-to-another"&gt;Migrate your service from one region to another&lt;/h2&gt;
&lt;p&gt;Now that the services are running, it’s time to demonstrate the power of cloud services operating in multiple clouds: migrating to a different cloud without losing any incoming data and without any downtime. Let’s perform a zero-downtime migration between regions.&lt;/p&gt;
&lt;p&gt;Start by changing your Aiven cloud region to a region in AWS (such as us-east-1). Then run the up command a second time.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi config &lt;span class="nb"&gt;set&lt;/span&gt; aiven_cloud_region aws-us-east-1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ pulumi up -y
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/pulumi-with-aiven-for-influxdb/pulumi_migrate.png" alt="Pulumi migrate"&gt;&lt;/p&gt;
&lt;p&gt;The output shows that two resources have changed, and both Grafana and the InfluxDB service show as rebuilding. A quick check in the Aiven console shows that both services are indeed being migrated to AWS:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/pulumi-with-aiven-for-influxdb/migrated_services.png" alt="Current services"&gt;&lt;/p&gt;
&lt;p&gt;If we switch back to Grafana, you can see that outside_temp_value is still being written to InfluxDB even as we migrate to a different cloud!&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.pulumi.com/blog/pulumi-with-aiven-for-influxdb/grafana.png" alt="Grafana"&gt;&lt;/p&gt;
&lt;h2 id="clean-up"&gt;Clean up&lt;/h2&gt;
&lt;p&gt;After we do projects, we need to tidy up after ourselves. Use the following commands to tear down the provisioned resources:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pulumi destroy
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pulumi stack rm &amp;lt;my-stack-name-here&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="python-code-details"&gt;Python code details&lt;/h2&gt;
&lt;h3 id="lambda-function"&gt;Lambda function&lt;/h3&gt;
&lt;p&gt;The lambda function is quite simple: a JSON payload is created for our randomly generated temperature reading, which is then passed to the InfluxDBClient for writing to the provisioned InfluxDB database. The automatically assigned Aiven service URI is added as an environment variable to the lambda function by Pulumi.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lambda_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;# Get the URL (including username and password) of the provisioned service instance&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;uri&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;SERVICE_URI&amp;#39;&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="n"&gt;urllib3&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;disable_warnings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;urllib3&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exceptions&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;InsecureRequestWarning&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="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;InfluxDBClient&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;from_dsn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ssl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;# Write our sample data&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;json_body&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;measurement&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;outside_temp&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="s2"&gt;&amp;#34;fields&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;value&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uniform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;130&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="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;try&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="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write_points&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_body&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;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;except&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Failed to send metrics to influxdb&amp;#39;&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;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="lambda-layer"&gt;Lambda layer&lt;/h3&gt;
&lt;p&gt;Because this function depends on the influxdb-client-python library, a custom Lambda Layer is created and assigned to the function in the Pulumi script. Inside the layer, you will notice a python folder that allows Lambda to load the module automatically.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;lambda_layer
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; └───python
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; └───influxdb-client-python
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="aiven-services"&gt;Aiven services&lt;/h3&gt;
&lt;p&gt;All of the Pulumi specific code resides in &lt;code&gt;__main__.py&lt;/code&gt;. Even though creating Aiven services in Pulumi is very straightforward, I have created a wrapper function named create_service to make this even easier.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;grafana&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;create_service&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;pulumi-grafana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;startup-4&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;grafana&amp;#34;&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;Simply pass in the &lt;a href="https://aiven.io/pricing"&gt;plan&lt;/a&gt; name, service type (Grafana in this case) and give your new service a name. The project name and cloud region are read in from the Pulumi config class.&lt;/p&gt;
&lt;p&gt;Creating &lt;a href="https://aiven.io/service-integrations"&gt;service integrations&lt;/a&gt; follows a similar paradigm:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;create_integration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;pulumi-grafana-influxdb&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;dashboard&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;influxdb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;grafana&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;When creating an integration, you have to specify the integration type and both the source and sink resource names. Here, we want to visualize our metrics in Grafana,which is an integration of type &lt;code&gt;dashboard&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="lambda-function-creation"&gt;Lambda function creation&lt;/h3&gt;
&lt;p&gt;Creating the Lambda function in AWS a tad more complicated, but this boils down to the methods below:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;lambda_func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;create_lambda&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;influxdb&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="n"&gt;create_lambda_trigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lambda_func&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;These methods initiate the following logic:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create an IAM role for the Lambda function&lt;/li&gt;
&lt;li&gt;Create the Lambda Layer, which includes our library dependencies&lt;/li&gt;
&lt;li&gt;Create the serverless function itself with environment variables, customer layer, and associated IAM policy&lt;/li&gt;
&lt;li&gt;Create the CloudWatch event rule to run the Lambda function every minute&lt;/li&gt;
&lt;li&gt;Sets the permissions of the function to allow it to be triggered by the CloudWatch event rule we just created&lt;/li&gt;
&lt;li&gt;Sets the EventBridge target to the Lambda function&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="wrapping-up"&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;In this article, I’ve demonstrated one way to deploy infrastructure as code in a manner that allows services to be migrated between clouds without any downtime. We also showed how InfluxDB could be used as an open source time-series backend for collecting temperature metrics.&lt;/p&gt;
&lt;p&gt;This same approach can be utilized for any &lt;a href="https://aiven.io/"&gt;Aiven’s&lt;/a&gt; services, including managed &lt;a href="https://aiven.io/kafka"&gt;Kafka&lt;/a&gt; and &lt;a href="https://aiven.io/postgresql"&gt;PostgreSQL&lt;/a&gt;. Sign up for a &lt;a href="https://console.aiven.io/signup"&gt;free 14-day trial&lt;/a&gt; and modify the lambda function to begin storing your own metrics data today.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;About the Author&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Trevor Kennedy is DataOps engineer who has spent 15+ years consulting in the public sector, telecommunications, financial services, insurance and energy industries. He has experience with all things data (data engineering, database development, data architecture, cloud migrations, and cloud architecture) on multiple platforms (on-premise, AWS, Azure and GCP) using both SQL, NoSQL &amp;amp; NewSQL technologies. Currently based in Austin, TX.&lt;/p&gt;
&lt;/blockquote&gt;</description><author>Trevor Kennedy</author><category>aws</category><category>python</category><category>aiven</category></item></channel></rss>