예제 #1
0
        public void SNSTestMessageTestEventFalse()
        {
            // ARRANGE
            string Json = @"
""Event"":""s3:TestEvent""
}";

            // ACT


            // ASSERT
            Assert.False(S3TestMessage.IsTestMessage(Json));
        }
예제 #2
0
        public void SNSTestMessageTestEventTrue()
        {
            // ARRANGE
            string Json = @"{
""Service"":""Amazon S3"",
""Event"":""s3:TestEvent"",
""Time"":""2014-10-13T15:57:02.089Z"",
""Bucket"":""bucketname"",
""RequestId"":""5582815E1AEA5ADF"",
""HostId"":""8cLeGAmw098X5cv4Zkwcmo8vvZa3eH3eKxsPzbB9wrR+YstdA6Knx4Ip8EXAMPLE""
}";

            // ACT


            // ASSERT
            Assert.True(S3TestMessage.IsTestMessage(Json));
        }
예제 #3
0
        /// <summary>
        /// Entrypoint for the Lambda function
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task ExecSNS(SNSEvent request, ILambdaContext context)
        {
            string DestinationBucket;

            if (String.IsNullOrEmpty(DestinationBucket = await GetDestinationBucket(context)))
            {
                return;
            }

            string PrefixPattern;

            if (String.IsNullOrEmpty(PrefixPattern = await GetPrefixPattern(context)))
            {
                return;
            }

            bool DeleteSource = false;

            Boolean.TryParse(Environment.GetEnvironmentVariable("DELETE_SOURCE"), out DeleteSource);

            foreach (SNSRecord Record in request.Records)
            {
                try
                {
                    string Message = Record.Sns.Message;

                    if (S3TestMessage.IsTestMessage(Message))
                    {
                        context.LogInfo($"Processing test event from SNS: {Message}");
                        return;
                    }

                    SNSS3RecordSet RecordSet = JsonConvert.DeserializeObject <SNSS3RecordSet>(Message);

                    foreach (SNSS3Record S3Record in RecordSet.Records)
                    {
                        try
                        {
                            string Key    = S3Record.S3.Object.Key;
                            string Bucket = S3Record.S3.Bucket.Name;

                            CopyObjectResponse Response = await Copy(Bucket, Key, DestinationBucket, PrefixPattern, context);
                        }
                        catch (AggregateException e)
                        {
                            context.LogError(e);

                            await SendFailureSNS(e.InnerException, context);
                        }
                        catch (Exception e)
                        {
                            context.LogError(e);

                            await SendFailureSNS(e, context);
                        }
                    }
                }
                catch (AggregateException e)
                {
                    context.LogError(e);

                    await SendFailureSNS(e.InnerException, context);
                }
                catch (Exception e)
                {
                    context.LogError(e);

                    await SendFailureSNS(e, context);
                }
            }
        }