Execute scheduled query - Amazon Timestream

Execute scheduled query

You can use the following code snippets to run a scheduled query.

public void executeScheduledQueries(String scheduledQueryArn, Date invocationTime) { System.out.println("Executing Scheduled Query"); try { ExecuteScheduledQueryResult executeScheduledQueryResult = queryClient.executeScheduledQuery(new ExecuteScheduledQueryRequest() .withScheduledQueryArn(scheduledQueryArn) .withInvocationTime(invocationTime) ); } catch (ResourceNotFoundException e) { System.out.println("Scheduled Query doesn't exist"); throw e; } catch (Exception e) { System.out.println("Execution Scheduled Query failed: " + e); throw e; } }
Java v2
public void executeScheduledQuery(String scheduledQueryArn) { System.out.println("Executing Scheduled Query"); try { ExecuteScheduledQueryResponse executeScheduledQueryResult = queryClient.executeScheduledQuery(ExecuteScheduledQueryRequest.builder() .scheduledQueryArn(scheduledQueryArn) .invocationTime(Instant.now()) .build() ); System.out.println("Execute ScheduledQuery response code: " + executeScheduledQueryResult.sdkHttpResponse().statusCode()); } catch (ResourceNotFoundException e) { System.out.println("Scheduled Query doesn't exist"); throw e; } catch (Exception e) { System.out.println("Execution Scheduled Query failed: " + e); throw e; } }
func (timestreamBuilder TimestreamBuilder) ExecuteScheduledQuery(scheduledQueryArn string, invocationTime time.Time) error { executeScheduledQueryInput := &timestreamquery.ExecuteScheduledQueryInput{ ScheduledQueryArn: aws.String(scheduledQueryArn), InvocationTime: aws.Time(invocationTime), } executeScheduledQueryOutput, err := timestreamBuilder.QuerySvc.ExecuteScheduledQuery(executeScheduledQueryInput) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case timestreamquery.ErrCodeResourceNotFoundException: fmt.Println(timestreamquery.ErrCodeResourceNotFoundException, aerr.Error()) default: fmt.Printf("Error: %s", aerr.Error()) } } else { fmt.Printf("Error: %s", err.Error()) } return err } else { fmt.Println("ExecuteScheduledQuery is successful, below is the output:") fmt.Println(executeScheduledQueryOutput.GoString()) return nil } }
def execute_scheduled_query(self, scheduled_query_arn, invocation_time): print("\nExecuting Scheduled Query") try: self.query_client.execute_scheduled_query(ScheduledQueryArn=scheduled_query_arn, InvocationTime=invocation_time) print("Successfully started executing scheduled query") except self.query_client.exceptions.ResourceNotFoundException as err: print("Scheduled Query doesn't exist") raise err except Exception as err: print("Scheduled Query execution failed:", err) raise err

The following snippet uses the AWS SDK for JavaScript V2 style. It is based on the sample application at Node.js sample Amazon Timestream for LiveAnalytics application on GitHub.

async function executeScheduledQuery(scheduledQueryArn, invocationTime) { console.log("Executing Scheduled Query"); var params = { ScheduledQueryArn: scheduledQueryArn, InvocationTime: invocationTime } try { await queryClient.executeScheduledQuery(params).promise(); } catch (err) { console.log("Execute Scheduled Query failed: ", err); throw err; } }
private async Task ExecuteScheduledQuery(string scheduledQueryArn, DateTime invocationTime) { try { Console.WriteLine("Running Scheduled Query"); await _amazonTimestreamQuery.ExecuteScheduledQueryAsync(new ExecuteScheduledQueryRequest() { ScheduledQueryArn = scheduledQueryArn, InvocationTime = invocationTime }); Console.WriteLine("Successfully started manual run of scheduled query"); } catch (ResourceNotFoundException e) { Console.WriteLine($"Scheduled Query doesn't exist: {e}"); throw; } catch (Exception e) { Console.WriteLine($"Execute Scheduled Query failed: {e}"); throw; } }