Show / Hide Table of Contents

Class LambdaFunctionDependencyProvider

The LambdaFunctionDependencyProvider class provides all the default, runtime dependencies for ALambdaFunction instances. Classes derived from ALambdaFunction that require additional dependencies should create their own Dependency Provider interface, derived from ILambdaFunctionDependencyProvider with a companion implementation class derived from LambdaFunctionDependencyProvider.

This separation of concerns makes it simple to create isolated unit tests to validate the behavior of the Lambda function implementation. For convenience sake, classes derived from ALambdaFunction should provide both an empty constructor that instantiate the default implementation and a constructor with that takes an instance implementing the required Dependency Provider interface.

Inheritance
System.Object
LambdaFunctionDependencyProvider
Implements
ILambdaFunctionDependencyProvider
Namespace: LambdaSharp
Assembly: LambdaSharp.dll
Syntax
public class LambdaFunctionDependencyProvider : ILambdaFunctionDependencyProvider

Constructors

LambdaFunctionDependencyProvider(Func<DateTime>, Action<String>, ILambdaConfigSource, IAmazonKeyManagementService, IAmazonSQS, IAmazonCloudWatchEvents, Nullable<Boolean>)

Create new instance of LambdaFunctionDependencyProvider, which provides the implementation for the required dependencies for ALambdaFunction.

Declaration
public LambdaFunctionDependencyProvider(Func<DateTime> utcNowCallback = null, Action<string> logCallback = null, ILambdaConfigSource configSource = null, IAmazonKeyManagementService kmsClient = null, IAmazonSQS sqsClient = null, IAmazonCloudWatchEvents eventsClient = null, bool? debugLoggingEnabled = default(bool? ))
Parameters
Type Name Description
System.Func<System.DateTime> utcNowCallback

A function that return the current DateTime in UTC timezone. Defaults to System.DateTime.UtcNow when null.

System.Action<System.String> logCallback

An action that logs a string message. Defaults to Amazon.Lambda.Core.LambdaLogger.Log(System.String) when null.

ILambdaConfigSource configSource

A ILambdaConfigSource instance from which the Lambda function configuration is read. Defaults to LambdaSystemEnvironmentSource instance when null.

Amazon.KeyManagementService.IAmazonKeyManagementService kmsClient

A Amazon.KeyManagementService.IAmazonKeyManagementService client instance. Defaults to Amazon.KeyManagementService.AmazonKeyManagementServiceClient when null.

Amazon.SQS.IAmazonSQS sqsClient

A Amazon.SQS.IAmazonSQS client instance. Defaults to Amazon.SQS.AmazonSQSClient when null.

Amazon.CloudWatchEvents.IAmazonCloudWatchEvents eventsClient

A Amazon.CloudWatchEvents.IAmazonCloudWatchEvents client instance. Defaults to Amazon.CloudWatchEvents.AmazonCloudWatchEventsClient when null.

System.Nullable<System.Boolean> debugLoggingEnabled

A boolean indicating if debug logging is enabled.

Properties

ConfigSource

Retrieves the ILambdaConfigSource instance used for initializing the Lambda function.

Declaration
public ILambdaConfigSource ConfigSource { get; }
Property Value
Type Description
ILambdaConfigSource

The ILambdaConfigSource instance.

DebugLoggingEnabled

The DebugLoggingEnabled property indicates if debug log entries should be emitted to CloudWatch logs.

Declaration
public bool DebugLoggingEnabled { get; }
Property Value
Type Description
System.Boolean

EventsClient

Retrieves the Amazon.CloudWatchEvents.IAmazonCloudWatchEvents instance used for communicating with Amazon EventBridge service.

Declaration
public IAmazonCloudWatchEvents EventsClient { get; }
Property Value
Type Description
Amazon.CloudWatchEvents.IAmazonCloudWatchEvents

KmsClient

Retrieves the Amazon.KeyManagementService.IAmazonKeyManagementService instance used for communicating with the AWS Key Management Service (KMS) service.

Declaration
public IAmazonKeyManagementService KmsClient { get; }
Property Value
Type Description
Amazon.KeyManagementService.IAmazonKeyManagementService

SqsClient

Retrieves the Amazon.SQS.IAmazonSQS instance used for communicating with the Amazon Simple Queue Service (SQS) service.

Declaration
public IAmazonSQS SqsClient { get; }
Property Value
Type Description
Amazon.SQS.IAmazonSQS

UtcNow

Retrieves the current date-time in UTC timezone.

Declaration
public DateTime UtcNow { get; }
Property Value
Type Description
System.DateTime

Current System.DateTime in UTC timezone

Methods

DecryptSecretAsync(Byte[], Dictionary<String, String>, CancellationToken)

Decrypt a sequence of bytes with an optional encryption context. The Lambda function requires permission to use the kms:Decrypt operation on the KMS key used to encrypt the original message.

Declaration
public virtual Task<byte[]> DecryptSecretAsync(byte[] secretBytes, Dictionary<string, string> encryptionContext, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Byte[] secretBytes

Array containing the encrypted bytes.

System.Collections.Generic.Dictionary<System.String, System.String> encryptionContext

An optional encryption context. Can be null.

System.Threading.CancellationToken cancellationToken

The token to monitor for cancellation requests.

Returns
Type Description
System.Threading.Tasks.Task<System.Byte[]>

The task object representing the asynchronous operation.

EncryptSecretAsync(Byte[], String, Dictionary<String, String>, CancellationToken)

Encrypt a sequence of bytes using the specified KMS key. The Lambda function requires permission to use the kms:Encrypt opeartion on the specified KMS key.

Declaration
public virtual Task<byte[]> EncryptSecretAsync(byte[] plaintextBytes, string encryptionKeyId, Dictionary<string, string> encryptionContext, CancellationToken cancellationToken)
Parameters
Type Name Description
System.Byte[] plaintextBytes

Array containing plaintext byte to encrypt.

System.String encryptionKeyId

The KMS key ID used encrypt the plaintext bytes.

System.Collections.Generic.Dictionary<System.String, System.String> encryptionContext

An optional encryption context. Can be null.

System.Threading.CancellationToken cancellationToken

The token to monitor for cancellation requests.

Returns
Type Description
System.Threading.Tasks.Task<System.Byte[]>

The task object representing the asynchronous operation.

Log(String)

Write a message to the log stream. In production, this should be the CloudWatch log associated with the Lambda function.

Declaration
public virtual void Log(string message)
Parameters
Type Name Description
System.String message

Message to write to the log stream.

SendEventAsync(DateTimeOffset, String, String, String, String, IEnumerable<String>, CancellationToken)

Send a CloudWatch event with optional event details and resources it applies to. This event will be forwarded to the default EventBridge by LambdaSharp.Core (requires Core Services to be enabled).

Declaration
public virtual Task SendEventAsync(DateTimeOffset timestamp, string eventbus, string source, string detailType, string detail, IEnumerable<string> resources, CancellationToken cancellationToken)
Parameters
Type Name Description
System.DateTimeOffset timestamp

The timestamp of the event.

System.String eventbus

The event bus that will receive the event.

System.String source

The source application of the event.

System.String detailType

Free-form string used to decide what fields to expect in the event detail.

System.String detail

Optional data-structure serialized as JSON string. There is no other schema imposed. The data-structure may contain fields and nested subobjects.

System.Collections.Generic.IEnumerable<System.String> resources

Optional AWS or custom resources, identified by unique identifier (e.g. ARN), which the event primarily concerns. Any number, including zero, may be present.

System.Threading.CancellationToken cancellationToken

The token to monitor for cancellation requests.

Returns
Type Description
System.Threading.Tasks.Task

SendMessageToQueueAsync(String, String, IEnumerable<KeyValuePair<String, String>>, CancellationToken)

Send a message to the specified SQS queue. The Lambda function requires sqs:SendMessage permission on the specified SQS queue.

Declaration
public virtual Task SendMessageToQueueAsync(string deadLetterQueueUrl, string message, IEnumerable<KeyValuePair<string, string>> messageAttributes, CancellationToken cancellationToken)
Parameters
Type Name Description
System.String deadLetterQueueUrl

The SQS queue URL.

System.String message

The message to send.

System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String, System.String>> messageAttributes

Optional attributes for the message.

System.Threading.CancellationToken cancellationToken

The token to monitor for cancellation requests.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

Implements

ILambdaFunctionDependencyProvider
In This Article
Back to top Generated by DocFX