1. Answers
  2. How to Create an AWS CloudWatch Log Group with Pulumi

How do I create an AWS CloudWatch log group using Pulumi?

To create an AWS CloudWatch log group using Pulumi, you need to define the log group resource in your Pulumi program. The following TypeScript code demonstrates how to achieve this.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create a CloudWatch Log Group
const logGroup = new aws.cloudwatch.LogGroup("my-log-group", {
    // Specify the name of the log group
    name: "my-log-group",
    
    // Optionally, specify the retention period in days
    retentionInDays: 7,
});

// Export the name of the log group
export const logGroupName = logGroup.name;

In this Pulumi program:

  • We import the necessary Pulumi and AWS packages.
  • We create a new CloudWatch Log Group named my-log-group.
  • We set the retention period of the log group to 7 days (this is optional and can be adjusted or omitted).
  • Finally, we export the name of the log group so that it can be accessed after the stack is deployed.

This program sets up a CloudWatch log group that can be used to store and manage your log data.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up