/// <summary> /// This method is called for every Lambda invocation. This method takes in an S3 event object and can be used /// to respond to S3 notifications. /// </summary> /// <param name="evnt"></param> /// <param name="context"></param> /// <returns></returns> public async Task <string> FunctionHandler(S3Event evnt, ILambdaContext context) { var s3Event = evnt.Records?[0].S3; if (s3Event == null) { return(null); } try { var response = await this.S3Client.GetObjectAsync(s3Event.Bucket.Name, s3Event.Object.Key); JSONMapper.Initialize(); Console.WriteLine("Starting!"); Stopwatch stopWatch = Stopwatch.StartNew(); stopWatch.Start(); List <KeyValuePair <string, string> > jsonCollection = new List <KeyValuePair <string, string> >(); string eventPayload = string.Empty; using (var stream = response.ResponseStream) { TextReader tr = new StreamReader(stream); eventPayload = tr.ReadToEnd(); Console.WriteLine("Handler: Got Data from Key"); } EventManager em = new EventManager(eventPayload); var returnobj = em.ProcessLambdaEvent(); Console.WriteLine("Enroll Member Time taken: {0}ms", stopWatch.Elapsed.TotalMilliseconds); Console.ReadLine(); return(response.Headers.ContentType); } catch (Exception e) { context.Logger.LogLine($"Error getting object {s3Event.Object.Key} from bucket {s3Event.Bucket.Name}. Make sure they exist and your bucket is in the same region as this function."); context.Logger.LogLine(e.Message); context.Logger.LogLine(e.StackTrace); throw; } }
public async Task <string> GetEventMap(string BucketName, string FileKey) { IAmazonS3 S3Client = new AmazonS3Client("AKIAIAYIN7WKAGAFBTDA", "zxa+XMi4ORN8sk5cXsqEozq2Q1Wcwac1xOPrkwyB", "EUWest1"); var response = await S3Client.GetObjectAsync(BucketName, FileKey); JSONMapper.Initialize(); Console.WriteLine("Starting!"); Stopwatch stopWatch = Stopwatch.StartNew(); stopWatch.Start(); List <KeyValuePair <string, string> > jsonCollection = new List <KeyValuePair <string, string> >(); string eventPayload = string.Empty; using (var stream = response.ResponseStream) { TextReader tr = new StreamReader(stream); eventPayload = tr.ReadToEnd(); Console.WriteLine("Handler: Got Data from Key"); } return(eventPayload); }