1. Packages
  2. AWS Classic
  3. API Docs
  4. cloudwatch
  5. QueryDefinition

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.23.0 published on Thursday, Feb 22, 2024 by Pulumi

aws.cloudwatch.QueryDefinition

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.23.0 published on Thursday, Feb 22, 2024 by Pulumi

    Provides a CloudWatch Logs query definition resource.

    Example Usage

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var example = new Aws.CloudWatch.QueryDefinition("example", new()
        {
            LogGroupNames = new[]
            {
                "/aws/logGroup1",
                "/aws/logGroup2",
            },
            QueryString = @"fields @timestamp, @message
    | sort @timestamp desc
    | limit 25
    
    ",
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cloudwatch"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := cloudwatch.NewQueryDefinition(ctx, "example", &cloudwatch.QueryDefinitionArgs{
    			LogGroupNames: pulumi.StringArray{
    				pulumi.String("/aws/logGroup1"),
    				pulumi.String("/aws/logGroup2"),
    			},
    			QueryString: pulumi.String("fields @timestamp, @message\n| sort @timestamp desc\n| limit 25\n\n"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.cloudwatch.QueryDefinition;
    import com.pulumi.aws.cloudwatch.QueryDefinitionArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var example = new QueryDefinition("example", QueryDefinitionArgs.builder()        
                .logGroupNames(            
                    "/aws/logGroup1",
                    "/aws/logGroup2")
                .queryString("""
    fields @timestamp, @message
    | sort @timestamp desc
    | limit 25
    
                """)
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_aws as aws
    
    example = aws.cloudwatch.QueryDefinition("example",
        log_group_names=[
            "/aws/logGroup1",
            "/aws/logGroup2",
        ],
        query_string="""fields @timestamp, @message
    | sort @timestamp desc
    | limit 25
    
    """)
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const example = new aws.cloudwatch.QueryDefinition("example", {
        logGroupNames: [
            "/aws/logGroup1",
            "/aws/logGroup2",
        ],
        queryString: `fields @timestamp, @message
    | sort @timestamp desc
    | limit 25
    
    `,
    });
    
    resources:
      example:
        type: aws:cloudwatch:QueryDefinition
        properties:
          logGroupNames:
            - /aws/logGroup1
            - /aws/logGroup2
          queryString: |+
            fields @timestamp, @message
            | sort @timestamp desc
            | limit 25        
    

    Create QueryDefinition Resource

    new QueryDefinition(name: string, args: QueryDefinitionArgs, opts?: CustomResourceOptions);
    @overload
    def QueryDefinition(resource_name: str,
                        opts: Optional[ResourceOptions] = None,
                        log_group_names: Optional[Sequence[str]] = None,
                        name: Optional[str] = None,
                        query_string: Optional[str] = None)
    @overload
    def QueryDefinition(resource_name: str,
                        args: QueryDefinitionArgs,
                        opts: Optional[ResourceOptions] = None)
    func NewQueryDefinition(ctx *Context, name string, args QueryDefinitionArgs, opts ...ResourceOption) (*QueryDefinition, error)
    public QueryDefinition(string name, QueryDefinitionArgs args, CustomResourceOptions? opts = null)
    public QueryDefinition(String name, QueryDefinitionArgs args)
    public QueryDefinition(String name, QueryDefinitionArgs args, CustomResourceOptions options)
    
    type: aws:cloudwatch:QueryDefinition
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args QueryDefinitionArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args QueryDefinitionArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args QueryDefinitionArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args QueryDefinitionArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args QueryDefinitionArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    QueryDefinition Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The QueryDefinition resource accepts the following input properties:

    QueryString string
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    LogGroupNames List<string>
    Specific log groups to use with the query.
    Name string
    The name of the query.
    QueryString string
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    LogGroupNames []string
    Specific log groups to use with the query.
    Name string
    The name of the query.
    queryString String
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    logGroupNames List<String>
    Specific log groups to use with the query.
    name String
    The name of the query.
    queryString string
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    logGroupNames string[]
    Specific log groups to use with the query.
    name string
    The name of the query.
    query_string str
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    log_group_names Sequence[str]
    Specific log groups to use with the query.
    name str
    The name of the query.
    queryString String
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    logGroupNames List<String>
    Specific log groups to use with the query.
    name String
    The name of the query.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the QueryDefinition resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    QueryDefinitionId string
    The query definition ID.
    Id string
    The provider-assigned unique ID for this managed resource.
    QueryDefinitionId string
    The query definition ID.
    id String
    The provider-assigned unique ID for this managed resource.
    queryDefinitionId String
    The query definition ID.
    id string
    The provider-assigned unique ID for this managed resource.
    queryDefinitionId string
    The query definition ID.
    id str
    The provider-assigned unique ID for this managed resource.
    query_definition_id str
    The query definition ID.
    id String
    The provider-assigned unique ID for this managed resource.
    queryDefinitionId String
    The query definition ID.

    Look up Existing QueryDefinition Resource

    Get an existing QueryDefinition resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: QueryDefinitionState, opts?: CustomResourceOptions): QueryDefinition
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            log_group_names: Optional[Sequence[str]] = None,
            name: Optional[str] = None,
            query_definition_id: Optional[str] = None,
            query_string: Optional[str] = None) -> QueryDefinition
    func GetQueryDefinition(ctx *Context, name string, id IDInput, state *QueryDefinitionState, opts ...ResourceOption) (*QueryDefinition, error)
    public static QueryDefinition Get(string name, Input<string> id, QueryDefinitionState? state, CustomResourceOptions? opts = null)
    public static QueryDefinition get(String name, Output<String> id, QueryDefinitionState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    LogGroupNames List<string>
    Specific log groups to use with the query.
    Name string
    The name of the query.
    QueryDefinitionId string
    The query definition ID.
    QueryString string
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    LogGroupNames []string
    Specific log groups to use with the query.
    Name string
    The name of the query.
    QueryDefinitionId string
    The query definition ID.
    QueryString string
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    logGroupNames List<String>
    Specific log groups to use with the query.
    name String
    The name of the query.
    queryDefinitionId String
    The query definition ID.
    queryString String
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    logGroupNames string[]
    Specific log groups to use with the query.
    name string
    The name of the query.
    queryDefinitionId string
    The query definition ID.
    queryString string
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    log_group_names Sequence[str]
    Specific log groups to use with the query.
    name str
    The name of the query.
    query_definition_id str
    The query definition ID.
    query_string str
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
    logGroupNames List<String>
    Specific log groups to use with the query.
    name String
    The name of the query.
    queryDefinitionId String
    The query definition ID.
    queryString String
    The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.

    Import

    Using pulumi import, import CloudWatch query definitions using the query definition ARN. The ARN can be found on the “Edit Query” page for the query in the AWS Console. For example:

     $ pulumi import aws:cloudwatch/queryDefinition:QueryDefinition example arn:aws:logs:us-west-2:123456789012:query-definition:269951d7-6f75-496d-9d7b-6b7a5486bdbd
    

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.23.0 published on Thursday, Feb 22, 2024 by Pulumi