Esempio n. 1
0
        async Task ConfigureLambdaWithQueueAsync(string queueName)
        {
            string queueArn = null;

            AmazonSQSClient sqsClient = AwsFactory.CreateClient <AmazonSQSClient>();

            GetQueueUrlRequest queueUrlReq = new GetQueueUrlRequest();

            queueUrlReq.QueueName = queueName;

            GetQueueUrlResponse getQueueUrlResp = await sqsClient.GetQueueUrlAsync(queueUrlReq);

            GetQueueAttributesRequest queueAttribReq = new GetQueueAttributesRequest();

            queueAttribReq.AttributeNames.Add(QueueAttributeName.QueueArn);
            queueAttribReq.QueueUrl = getQueueUrlResp.QueueUrl;

            var queueAttribResp = await sqsClient.GetQueueAttributesAsync(queueAttribReq);

            queueArn = queueAttribResp.QueueARN;

            AmazonLambdaClient lambdaClient = AwsFactory.CreateClient <AmazonLambdaClient>();

            CreateEventSourceMappingRequest eventMappingReq = new CreateEventSourceMappingRequest();

            eventMappingReq.FunctionName   = "WebhookDispatcher";
            eventMappingReq.BatchSize      = 10;
            eventMappingReq.Enabled        = true;
            eventMappingReq.EventSourceArn = queueArn;

            await lambdaClient.CreateEventSourceMappingAsync(eventMappingReq);
        }
Esempio n. 2
0
        public static async Task AddEventSourceAsync()
        {
            #region add_dynamodb_event_source
            using (var streamClient = new AmazonDynamoDBStreamsClient())
                using (var lambdaClient = new AmazonLambdaClient())
                {
                    // TODO: Enter Lambda function name, this is most likely: ServerlessTODOListStreamProcessor
                    var functionName = "";
                    if (string.IsNullOrEmpty(functionName))
                    {
                        Console.Error.WriteLine("You must set the name of the Lambda function you deployed to the \"functionName\" variable");
                        return;
                    }

                    var listRequest = new ListStreamsRequest
                    {
                        TableName = "TODOList"
                    };

                    var listResponse = await streamClient.ListStreamsAsync(listRequest);

                    if (listResponse.Streams.Count == 0)
                    {
                        Console.Error.WriteLine($"A stream is not enabled for the table {listRequest.TableName}");
                        return;
                    }

                    var streamArn = listResponse.Streams[0].StreamArn;
                    Console.WriteLine($"Stream ARN is {streamArn}");

                    var request = new CreateEventSourceMappingRequest
                    {
                        FunctionName     = functionName,
                        EventSourceArn   = streamArn,
                        StartingPosition = EventSourcePosition.LATEST,
                        BatchSize        = 100
                    };

                    await lambdaClient.CreateEventSourceMappingAsync(request);

                    Console.WriteLine($"Event source mapping made between stream {streamArn} and function {functionName}");
                }
            #endregion
        }