public LayerTestsFixture() { this.CFClient = new AmazonCloudFormationClient(RegionEndpoint.USEast1); this.S3Client = new AmazonS3Client(RegionEndpoint.USEast1); this.LambdaClient = new AmazonLambdaClient(RegionEndpoint.USEast1); this.Bucket = "dotnet-lambda-layer-tests-" + DateTime.Now.Ticks; Task.Run(async() => { await S3Client.PutBucketAsync(this.Bucket); // Wait for bucket to exist Thread.Sleep(10000); }).Wait(); }
private static async Task Main(string[] args) { // // Go here and login with your account to create an access key: https://console.aws.amazon.com/iam/home?#/security_credentials // //Uncomment this line if you want to use it against your own bucket //using (S3Client client = AmazonClient.Create("YourKeyIdHere", "YourAccessKeyHere")) using (S3Client client = MinioPlaygroundClient.Create()) { const string bucketName = "simple-s3-test"; const string objectName = "some-object"; //First we create the a bucket named "simple-s3-test". It might already be there, so we ignore if the request was not a success await client.PutBucketAsync(bucketName).ConfigureAwait(false); //Then we upload an object named "some-object" to the bucket. It contains "Hello World" inside it. if (await UploadObject(client, bucketName, objectName).ConfigureAwait(false)) { Console.WriteLine("Successfully uploaded the object"); GetObjectResponse resp = await DownloadObject(client, bucketName, objectName).ConfigureAwait(false); //Here we try to download the object again. If successful, we should see it print the content to the screen. if (resp.IsSuccess) { Console.WriteLine("Successfully downloaded the object"); string content = await resp.Content.AsStringAsync().ConfigureAwait(false); Console.WriteLine("The object contained: " + content); //Finally, we clean up after us and remove the object. if (await DeleteObject(client, bucketName, objectName).ConfigureAwait(false)) { Console.WriteLine("Successfully deleted the object"); } } } } }
public async Task CreateQueueIfNecessary(string address) { try { var queueName = SqsQueueNameHelper.GetSqsQueueName(address, ConnectionConfiguration); var sqsRequest = new CreateQueueRequest { QueueName = queueName, }; Logger.Info($"Creating SQS Queue with name \"{sqsRequest.QueueName}\" for address \"{address}\"."); var createQueueResponse = await SqsClient.CreateQueueAsync(sqsRequest).ConfigureAwait(false); QueueUrlCache.SetQueueUrl(queueName, createQueueResponse.QueueUrl); // Set the queue attributes in a separate call. // If you call CreateQueue with a queue name that already exists, and with a different // value for MessageRetentionPeriod, the service throws. This will happen if you // change the MaxTTLDays configuration property. var sqsAttributesRequest = new SetQueueAttributesRequest { QueueUrl = createQueueResponse.QueueUrl }; sqsAttributesRequest.Attributes.Add(QueueAttributeName.MessageRetentionPeriod, ((int)(TimeSpan.FromDays(ConnectionConfiguration.MaxTTLDays).TotalSeconds)).ToString()); await SqsClient.SetQueueAttributesAsync(sqsAttributesRequest).ConfigureAwait(false); if (!string.IsNullOrEmpty(ConnectionConfiguration.S3BucketForLargeMessages)) { // determine if the configured bucket exists; create it if it doesn't var listBucketsResponse = await S3Client.ListBucketsAsync(new ListBucketsRequest()).ConfigureAwait(false); var bucketExists = listBucketsResponse.Buckets.Any(x => string.Equals(x.BucketName, ConnectionConfiguration.S3BucketForLargeMessages, StringComparison.InvariantCultureIgnoreCase)); if (!bucketExists) { await S3Client.RetryConflictsAsync(async() => await S3Client.PutBucketAsync(new PutBucketRequest { BucketName = ConnectionConfiguration.S3BucketForLargeMessages }).ConfigureAwait(false), onRetry : x => { Logger.Warn($"Conflict when creating S3 bucket, retrying after {x}ms."); }).ConfigureAwait(false); } var lifecycleConfig = await S3Client.GetLifecycleConfigurationAsync(ConnectionConfiguration.S3BucketForLargeMessages).ConfigureAwait(false); bool setLifecycleConfig = lifecycleConfig.Configuration.Rules.All(x => x.Id != "NServiceBus.SQS.DeleteMessageBodies"); if (setLifecycleConfig) { await S3Client.RetryConflictsAsync(async() => await S3Client.PutLifecycleConfigurationAsync(new PutLifecycleConfigurationRequest { BucketName = ConnectionConfiguration.S3BucketForLargeMessages, Configuration = new LifecycleConfiguration { Rules = new List <LifecycleRule> { new LifecycleRule { Id = "NServiceBus.SQS.DeleteMessageBodies", Filter = new LifecycleFilter { LifecycleFilterPredicate = new LifecyclePrefixPredicate { Prefix = ConnectionConfiguration.S3KeyPrefix } }, Status = LifecycleRuleStatus.Enabled, Expiration = new LifecycleRuleExpiration { Days = ConnectionConfiguration.MaxTTLDays } } } } }).ConfigureAwait(false), onRetry : x => { Logger.Warn($"Conflict when setting S3 lifecycle configuration, retrying after {x}ms."); }).ConfigureAwait(false); } } } catch (Exception e) { Logger.Error("Exception from CreateQueueIfNecessary.", e); throw; } }