1. Answers
  2. Building an AWS CloudWatch Log Group

How do I build an AWS CloudWatch Log Group?

To create an AWS CloudWatch Log Group using Pulumi, you can use the aws.cloudwatch.LogGroup resource. Below is a TypeScript program that demonstrates how to define and create a CloudWatch Log Group in AWS.

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", {
    name: "my-log-group",
    retentionInDays: 14, // Retain logs for 14 days
});

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

This program does the following:

  1. Imports the necessary Pulumi and AWS packages.
  2. Creates a CloudWatch Log Group named “my-log-group” with a retention period of 14 days.
  3. Exports the name of the created log group.

In summary, this program demonstrates how to create and manage an AWS CloudWatch Log Group using Pulumi, including setting a retention policy for the logs.

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