How Do I Deploy InfluxDB on AWS EC2 Using Pulumi and TypeScript?
In this example, we will deploy the latest InfluxDB Docker image on an AWS EC2 instance using Pulumi with TypeScript. We will set up an EC2 instance, install Docker, and run the InfluxDB container.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create a new security group for the EC2 instance
const securityGroup = new aws.ec2.SecurityGroup("influxdb-secgrp", {
description: "Allow HTTP and InfluxDB access",
ingress: [
{ protocol: "tcp", fromPort: 22, toPort: 22, cidrBlocks: ["0.0.0.0/0"] }, // SSH
{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] }, // HTTP
{ protocol: "tcp", fromPort: 8086, toPort: 8086, cidrBlocks: ["0.0.0.0/0"] }, // InfluxDB
],
});
// Get the latest Amazon Linux 2 AMI
const ami = aws.ec2.getAmi({
filters: [
{ name: "name", values: ["amzn2-ami-hvm-*-x86_64-gp2"] },
],
owners: ["137112412989"], // Amazon
mostRecent: true,
}).then(ami => ami.id);
// Create a new EC2 instance
const server = new aws.ec2.Instance("influxdb-server", {
instanceType: "t2.micro",
securityGroups: [securityGroup.name],
ami: ami,
userData: `#!/bin/bash
sudo yum update -y
sudo amazon-linux-extras install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo docker run -d -p 8086:8086 influxdb:latest`,
tags: {
Name: "influxdb-server",
},
});
// Export the public IP of the instance
export const publicIp = server.publicIp;
export const publicDns = server.publicDns;
Key Points
- Created a security group to allow SSH, HTTP, and InfluxDB traffic.
- Used the latest Amazon Linux 2 AMI for the EC2 instance.
- Configured the EC2 instance to install Docker and run the InfluxDB container.
- Exported the public IP and DNS of the EC2 instance for easy access.
Summary
We have successfully deployed the InfluxDB Docker image on an AWS EC2 instance using Pulumi with TypeScript. This setup includes creating a security group, launching an EC2 instance, installing Docker, and running the InfluxDB container.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.