internal CreateEventSourceMappingResponse CreateEventSourceMapping(CreateEventSourceMappingRequest request) { var marshaller = new CreateEventSourceMappingRequestMarshaller(); var unmarshaller = CreateEventSourceMappingResponseUnmarshaller.Instance; return(Invoke <CreateEventSourceMappingRequest, CreateEventSourceMappingResponse>(request, marshaller, unmarshaller)); }
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); }
/// <summary> /// Initiates the asynchronous execution of the CreateEventSourceMapping operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateEventSourceMapping operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <CreateEventSourceMappingResponse> CreateEventSourceMappingAsync(CreateEventSourceMappingRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new CreateEventSourceMappingRequestMarshaller(); var unmarshaller = CreateEventSourceMappingResponseUnmarshaller.Instance; return(InvokeAsync <CreateEventSourceMappingRequest, CreateEventSourceMappingResponse>(request, marshaller, unmarshaller, cancellationToken)); }
public static string CreateEventSourceMapping(string eventSourceArn) { string uuid = ""; try { AmazonLambdaClient lambdaClient; using (lambdaClient = new AmazonLambdaClient(Models.MyAWSConfigs.KinesisRegion)) { CreateEventSourceMappingRequest eventSourceMappingRequest = new CreateEventSourceMappingRequest { EventSourceArn = eventSourceArn, BatchSize = 100, MaximumBatchingWindowInSeconds = 0, StartingPosition = EventSourcePosition.LATEST, Enabled = true, FunctionName = MyAWSConfigs.LambdaFunctionName, }; CreateEventSourceMappingResponse eventSourceMappingResponse = lambdaClient.CreateEventSourceMapping(eventSourceMappingRequest); uuid = eventSourceMappingResponse.UUID; string state = eventSourceMappingResponse.State; while (state != "Enabled") { Thread.Sleep(1 * 1000); GetEventSourceMappingRequest getRequest = new GetEventSourceMappingRequest { UUID = uuid, }; GetEventSourceMappingResponse getResponse = lambdaClient.GetEventSourceMapping(getRequest); state = getResponse.State; } } } catch (AmazonLambdaException e) { Console.WriteLine("AmazonLambdaException: " + e); } catch (Exception e) { Console.WriteLine("Error: " + e); } return(uuid); }
/// <summary> /// Initiates the asynchronous execution of the CreateEventSourceMapping operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateEventSourceMapping operation on AmazonLambdaClient.</param> /// <param name="callback">An Action delegate that is invoked when the operation completes.</param> /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> public void CreateEventSourceMappingAsync(CreateEventSourceMappingRequest request, AmazonServiceCallback <CreateEventSourceMappingRequest, CreateEventSourceMappingResponse> callback, AsyncOptions options = null) { options = options == null?new AsyncOptions():options; var marshaller = new CreateEventSourceMappingRequestMarshaller(); var unmarshaller = CreateEventSourceMappingResponseUnmarshaller.Instance; Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null; if (callback != null) { callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { AmazonServiceResult <CreateEventSourceMappingRequest, CreateEventSourceMappingResponse> responseObject = new AmazonServiceResult <CreateEventSourceMappingRequest, CreateEventSourceMappingResponse>((CreateEventSourceMappingRequest)req, (CreateEventSourceMappingResponse)res, ex, ao.State); callback(responseObject); } } ; BeginInvoke <CreateEventSourceMappingRequest>(request, marshaller, unmarshaller, options, callbackHelper); }
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 }
public async Task Should_invoke_with_sqs_event_source_mapping() { await using var fixture = await LocalStackFixture.Create(_outputHelper); // 1.1 Arrange: Create dummy lambda function in localstack var functionInfo = fixture.LambdaTestHost.Settings.Functions.Last().Value; var createFunctionRequest = new CreateFunctionRequest { Handler = "dummy-handler", // ignored FunctionName = functionInfo.Name, // must match Role = "arn:aws:iam::123456789012:role/foo", // must be specified Code = new FunctionCode { ZipFile = new MemoryStream() // must be specified but is ignored } }; await fixture.LambdaClient.CreateFunctionAsync(createFunctionRequest); // 1.2 Arrange: Create queue and event source mapping var queueName = "test-queue"; var createQueueResponse = await fixture.SQSClient.CreateQueueAsync(queueName); var createEventSourceMappingRequest = new CreateEventSourceMappingRequest { FunctionName = functionInfo.Name, EventSourceArn = $"arn:aws:sqs:eu-west-1:123456789012:{queueName}", BatchSize = 1, Enabled = true, }; var createEventSourceMappingResponse = await fixture.LambdaClient.CreateEventSourceMappingAsync(createEventSourceMappingRequest); // 2. Act: send message to queue await fixture.SQSClient.SendMessageAsync(createQueueResponse.QueueUrl, "hello"); await Task.Delay(10000); }
public void CreateEventSourceMappingAsync(CreateEventSourceMappingRequest request, AmazonServiceCallback <CreateEventSourceMappingRequest, CreateEventSourceMappingResponse> callback, AsyncOptions options = null) { throw new System.NotImplementedException(); }