Class LambdaFunctionDependencyProvider
The Lambda
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 ALambda
Inheritance
Implements
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 Lambda
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 = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
utcNowCallback | A function that return the current |
System. |
logCallback | An action that logs a string message. Defaults to Amazon. |
ILambda |
configSource | A ILambda |
Amazon. |
kmsClient | A Amazon. |
Amazon. |
sqsClient | A Amazon. |
Amazon. |
eventsClient | A Amazon. |
System. |
debugLoggingEnabled | A boolean indicating if debug logging is enabled. |
Properties
ConfigSource
Retrieves the ILambda
Declaration
public ILambdaConfigSource ConfigSource { get; }
Property Value
Type | Description |
---|---|
ILambda |
The ILambda |
DebugLoggingEnabled
The Debug
Declaration
public bool DebugLoggingEnabled { get; }
Property Value
Type | Description |
---|---|
System. |
EventsClient
Retrieves the Amazon.
Declaration
public IAmazonCloudWatchEvents EventsClient { get; }
Property Value
Type | Description |
---|---|
Amazon. |
KmsClient
Retrieves the Amazon.
Declaration
public IAmazonKeyManagementService KmsClient { get; }
Property Value
Type | Description |
---|---|
Amazon. |
SqsClient
Retrieves the Amazon.
Declaration
public IAmazonSQS SqsClient { get; }
Property Value
Type | Description |
---|---|
Amazon. |
UtcNow
Retrieves the current date-time in UTC timezone.
Declaration
public DateTime UtcNow { get; }
Property Value
Type | Description |
---|---|
System. |
Current System. |
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 async Task<byte[]> DecryptSecretAsync(byte[] secretBytes, Dictionary<string, string> encryptionContext, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System. |
secretBytes | Array containing the encrypted bytes. |
System. |
encryptionContext | An optional encryption context. Can be |
System. |
cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
System. |
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 async Task<byte[]> EncryptSecretAsync(byte[] plaintextBytes, string encryptionKeyId, Dictionary<string, string> encryptionContext, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System. |
plaintextBytes | Array containing plaintext byte to encrypt. |
System. |
encryptionKeyId | The KMS key ID used encrypt the plaintext bytes. |
System. |
encryptionContext | An optional encryption context. Can be |
System. |
cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
System. |
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. |
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. |
timestamp | The timestamp of the event. |
System. |
eventbus | The event bus that will receive the event. |
System. |
source | The source application of the event. |
System. |
detailType | Free-form string used to decide what fields to expect in the event detail. |
System. |
detail | Optional data-structure serialized as JSON string. There is no other schema imposed. The data-structure may contain fields and nested subobjects. |
System. |
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. |
cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
System. |
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. |
deadLetterQueueUrl | The SQS queue URL. |
System. |
message | The message to send. |
System. |
messageAttributes | Optional attributes for the message. |
System. |
cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
System. |
The task object representing the asynchronous operation. |