AWS Code Sample
Catalog

subscribe_lambda.cpp

subscribe_lambda.cpp demonstrates how to initiate a subscription to an Amazon SNS topic with delivery to an AWS Lambda function.

/* Copyright 2010-2018 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/sns/SNSClient.h> #include <aws/sns/model/SubscribeRequest.h> #include <aws/sns/model/SubscribeResult.h> #include <iostream> /** * Subscribe to lambda */ int main(int argc, char ** argv) { if (argc != 4) { std::cout << "Usage: subscribe <protocol_value/lambda> <topic_arn_value>" "lambda_function_arn" << std::endl; return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { Aws::SNS::SNSClient sns; Aws::String protocol = argv[1]; Aws::String topic_arn = argv[2]; Aws::String endpoint = argv[3]; Aws::SNS::Model::SubscribeRequest s_req; s_req.SetTopicArn(topic_arn); s_req.SetProtocol(protocol); s_req.SetEndpoint(endpoint); auto s_out = sns.Subscribe(s_req); if (s_out.IsSuccess()) { std::cout << "Subscribed successfully " << std::endl; } else { std::cout << "Error while subscribing " << s_out.GetError().GetMessage() << std::endl; } } Aws::ShutdownAPI(options); return 0; }

Sample Details

Service: sns

Author: tapasweni-pathak

Type: full-example

On this page: