Skip to content
GitHubXDiscord

Dimension

The Dimension resource allows you to manage AWS IoT Dimensions that help in categorizing and filtering IoT data streams effectively.

This example demonstrates how to create a basic IoT Dimension with required properties and a common optional tag.

import AWS from "alchemy/aws/control";
const basicDimension = await AWS.IoT.Dimension("basicDimension", {
Type: "string",
StringValues: ["sensor", "device", "location"],
Tags: [
{
Key: "Environment",
Value: "Production"
}
]
});

In this example, we create an IoT Dimension with additional properties including a unique name and multiple string values.

const advancedDimension = await AWS.IoT.Dimension("advancedDimension", {
Type: "string",
StringValues: ["temperature", "humidity", "pressure"],
Name: "EnvironmentalParameters",
Tags: [
{
Key: "Application",
Value: "WeatherMonitoring"
},
{
Key: "Department",
Value: "Research"
}
]
});

This example demonstrates how to adopt an existing IoT Dimension instead of failing when the resource already exists.

const adoptedDimension = await AWS.IoT.Dimension("adoptedDimension", {
Type: "string",
StringValues: ["existingValue"],
adopt: true // This will adopt the existing dimension if it exists
});

Here’s how to reference an IoT Dimension within an IoT Rule to filter messages based on dimension values.

import AWS from "alchemy/aws/control";
const iotRule = await AWS.IoT.Rule("temperatureAlertRule", {
RuleName: "TemperatureAlert",
Sql: "SELECT * FROM 'sensor/temperature' WHERE dimension = 'high'",
Actions: [
{
Lambda: {
FunctionArn: "arn:aws:lambda:us-west-2:123456789012:function:alertFunction"
}
}
],
Tags: [
{
Key: "Status",
Value: "Active"
}
]
});