Exemplo n.º 1
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _amazonSnsClient?.Dispose();
            }

            base.Dispose(disposing);
        }
Exemplo n.º 2
0
        public async ValueTask DisposeAsync()
        {
            await _snsClient.DeleteTopicAsync(TopicArn);

            await _sqsClient.DeleteQueueAsync(QueueUrl);

            _snsClient.Dispose();
            _sqsClient.Dispose();
        }
        public static IAmazonSimpleNotificationService CreateSnsClient(this IAmazonSnsSettings amazonSnsSettings, ITransactionContext transactionContext)
        {
            return(transactionContext.GetOrAdd(AmazonConstaints.SnsClientContextKey, () =>
            {
                var client = new AmazonSimpleNotificationServiceClient(amazonSnsSettings.AmazonCredentialsFactory.Create(), amazonSnsSettings.AmazonSimpleNotificationServiceConfig);

                transactionContext.OnDisposed((ITransactionContext context) => client.Dispose());

                return client;
            }));
        }
Exemplo n.º 4
0
 /// <summary>
 /// </summary>
 protected sealed override void OnStop()
 {
     if (_clientSNS != null)
     {
         _clientSNS.Dispose();
         _clientSNS = null;
     }
     if (_clientCloudWatchLogs != null)
     {
         _clientCloudWatchLogs.Dispose();
         _clientCloudWatchLogs = null;
     }
 }
Exemplo n.º 5
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    _snsClient.Dispose();
                    _snsClient = null;
                }

                _disposed = true;
            }
        }
Exemplo n.º 6
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            if (_client == null)
            {
                return;
            }
            _client.Dispose();
            _client = null;
        }
Exemplo n.º 7
0
 public void Dispose() => Client.Dispose();
Exemplo n.º 8
0
 protected override void DisposeServices()
 {
     _simpleNotificationClient?.Dispose();
 }
Exemplo n.º 9
0
        static async Task <(string topicArn, Func <Task> cleanup)> CreateLambda(LambdaCreationOptions lambdaCreationOptions)
        {
            var    cleanup = new List <Func <Task> >();
            var    log     = lambdaCreationOptions.Verbose;
            string publishTopic;


            var lambdaClient = new AmazonLambdaClient();
            var snsClient    = new AmazonSimpleNotificationServiceClient();
            var iamClient    = new AmazonIdentityManagementServiceClient();

            cleanup.Add(() =>
            {
                lambdaClient.Dispose();
                snsClient.Dispose();
                iamClient.Dispose();
                return(Task.CompletedTask);
            });


            try
            {
                log("Creating IAM Role");
                var(roleArn, _, roleCleanup) =
                    await CreateRole(iamClient, lambdaCreationOptions.Timestamp, lambdaCreationOptions.Name,
                                     lambdaCreationOptions.CancellationToken);

                cleanup.Add(roleCleanup);

                log("Creating Function");
                var(functionArn, _, functionCleanup) =
                    await CreateFunction(roleArn,
                                         lambdaClient,
                                         lambdaCreationOptions);

                cleanup.Add(functionCleanup);

                log("Creating SNS Topic");
                var(topicArn, topicCleanup) =
                    await CreateTopic(snsClient, lambdaCreationOptions.Timestamp, lambdaCreationOptions.Name,
                                      lambdaCreationOptions.CancellationToken);

                cleanup.Add(topicCleanup);
                publishTopic = topicArn;

                log("Creating SNS Subscription");
                var subCleaner = await Subscribe(snsClient, functionArn, topicArn, lambdaCreationOptions.CancellationToken);

                cleanup.Add(subCleaner);

                log("Permissioning SNS to execute the function");
                var permCleanup = await AddExecutionFromSnsPermission(lambdaClient, functionArn, topicArn,
                                                                      lambdaCreationOptions.CancellationToken);

                cleanup.Add(permCleanup);
            }
            catch (Exception)
            {
                log("Cleaning up resources");
                await Cleanup(cleanup);

                throw;
            }

            return(publishTopic, () => Cleanup(cleanup));
        }
 /// <summary>
 /// Releases any unmanaged resources and disposes of the managed resources used
 /// by the <see cref="AmazonSnsService"/>.
 /// </summary>
 public void Dispose()
 {
     _snsClient?.Dispose();
 }