AWS Code Sample
Catalog

put_rule.cpp

put_rule.cpp demonstrates how to create an Amazon CloudWatch Events routing rule.

/* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <aws/core/Aws.h> #include <aws/events/CloudWatchEventsClient.h> #include <aws/events/model/PutRuleRequest.h> #include <aws/events/model/PutRuleResult.h> #include <aws/core/utils/Outcome.h> #include <iostream> /** * Creates a cloud watch event-routing rule, based on command line input */ int main(int argc, char** argv) { if (argc != 3) { std::cout << "Usage: put_rule <rule_name> <role_arn>" << std::endl; return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { Aws::String rule_name(argv[1]); Aws::String role_arn(argv[2]); Aws::CloudWatchEvents::CloudWatchEventsClient cwe; Aws::CloudWatchEvents::Model::PutRuleRequest request; request.SetName(rule_name); request.SetRoleArn(role_arn); request.SetScheduleExpression("rate(5 minutes)"); request.SetState(Aws::CloudWatchEvents::Model::RuleState::ENABLED); auto outcome = cwe.PutRule(request); if (!outcome.IsSuccess()) { std::cout << "Failed to create cloudwatch events rule " << rule_name << ": " << outcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully created cloudwatch events rule " << rule_name << " with resulting Arn " << outcome.GetResult().GetRuleArn() << std::endl; } } Aws::ShutdownAPI(options); return 0; }

Sample Details

Service: events

Author: AWS

Type: full-example

On this page: