Skip to content

Commit f02a712

Browse files
authored
Merge pull request #1 from sliedig/amirkaws-feature-parameters
docs: updates and fixes to docs for parametes
2 parents 8c9f41a + bd3c4db commit f02a712

File tree

6 files changed

+129
-29
lines changed

6 files changed

+129
-29
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AWS Lambda Powertools for .NET
22

3-
![aws provider](https://img.shields.io/badge/provider-AWS-orange?logo=amazon-aws&color=ff9900)
3+
![aws provider](https://img.shields.io/badge/provider-AWS-orange?logo=amazon-aws&color=ff9900)
44
[![Build](https://github.com/awslabs/aws-lambda-powertools-dotnet/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/awslabs/aws-lambda-powertools-dotnet/actions/workflows/build.yml)
55
[![Join our Discord](https://dcbadge.vercel.app/api/server/B8zZKbbyET)](https://discord.gg/B8zZKbbyET)
66

@@ -20,9 +20,11 @@ Lambda Powertools provides three core utilities:
2020

2121
* **[Tracing](https://awslabs.github.io/aws-lambda-powertools-dotnet/core/tracing/)** - provides a simple way to send traces from functions to AWS X-Ray to provide visibility into function calls, interactions with other AWS services, or external HTTP requests. Annotations can easily be added to traces to allow filtering traces based on key information. For example, when using Tracer, a ColdStart annotation is created for you so you can easily group and analyze traces where there was an initialization overhead.
2222

23+
* **[Parameters (developer preview)](https://awslabs.github.io/aws-lambda-powertools-dotnet/core/parameters/)** - provides high-level functionality to retrieve one or multiple parameter values from [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html){target="_blank"}, [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/){target="_blank"}, or [Amazon DynamoDB](https://aws.amazon.com/dynamodb/){target="_blank"}. We also provide extensibility to bring your own providers.
24+
2325
### Installation
2426

25-
The AWS Lambda Powertools for .NET utilities (.NET 6) are available as NuGet packages. You can install the packages from the NuGet gallery or from within the Visual Studio IDE. Search `AWS.Lambda.Powertools*` to see various utilities available. Powertools is available on NuGet.
27+
The AWS Lambda Powertools for .NET utilities (.NET 6) are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*){target="_blank"} or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available.
2628

2729
* [AWS.Lambda.Powertools.Logging](https://www.nuget.org/packages?q=AWS.Lambda.Powertools.Logging):
2830

@@ -36,6 +38,10 @@ The AWS Lambda Powertools for .NET utilities (.NET 6) are available as NuGet pac
3638

3739
`dotnet add package AWS.Lambda.Powertools.Tracing`
3840

41+
* [AWS.Lambda.Powertools.Parameters](https://www.nuget.org/packages?q=AWS.Lambda.Powertools.Parameters):
42+
43+
`dotnet add package AWS.Lambda.Powertools.AWS.Lambda.Powertools.Parameters`
44+
3945
## Examples
4046

4147
We have provided examples focused specifically on each of the utilities. Each solution comes with an AWS Serverless Application Model (AWS SAM) templates to run your functions as a Zip package using the AWS Lambda .NET 6 managed runtime; or as a container package using the AWS base images for .NET.
@@ -66,7 +72,7 @@ We welcome contributions from developers of all levels to our open-source projec
6672
## Connect
6773

6874
* **AWS Lambda Powertools on Discord**: `#dotnet` - **[Invite link](https://discord.gg/B8zZKbbyET)**
69-
* **Email**: [email protected]
75+
* **Email**: <[email protected]>
7076

7177
## License
7278

docs/core/logging.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ The logging utility provides a Lambda optimized logger with output structured as
1212
* Log sampling enables DEBUG log level for a percentage of requests (disabled by default)
1313
* Append additional keys to structured log at any point in time
1414

15+
## Installation
16+
17+
Powertools are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*){target="_blank"} or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available.
18+
19+
* [AWS.Lambda.Powertools.Logging](https://www.nuget.org/packages?q=AWS.Lambda.Powertools.Logging):
20+
21+
`dotnet add package AWS.Lambda.Powertools.Logging`
22+
1523
## Getting started
1624

1725
Logging requires two settings:

docs/core/metrics.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ These metrics can be visualized through [Amazon CloudWatch Console](https://aws.
99

1010
## Key features
1111

12-
* Aggregate up to 100 metrics using a single CloudWatch EMF object (large JSON blob)
12+
* Aggregate up to 100 metrics using a single [CloudWatch EMF](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html){target="_blank"} object (large JSON blob)
1313
* Validating your metrics against common metric definitions mistakes (for example, metric unit, values, max dimensions, max metrics)
1414
* Metrics are created asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency
1515
* Context manager to create a one off metric with a different dimension
@@ -21,6 +21,14 @@ These metrics can be visualized through [Amazon CloudWatch Console](https://aws.
2121
<figcaption>Metrics showcase - Metrics Explorer</figcaption>
2222
</figure>
2323

24+
## Installation
25+
26+
Powertools are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*){target="_blank"} or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available.
27+
28+
* [AWS.Lambda.Powertools.Metrics](https://www.nuget.org/packages?q=AWS.Lambda.Powertools.Metrics):
29+
30+
`dotnet nuget add AWS.Lambda.Powertools.Metrics`
31+
2432
## Terminologies
2533

2634
If you're new to Amazon CloudWatch, there are two terminologies you must be aware of before using this utility:
@@ -378,3 +386,21 @@ CloudWatch EMF uses the same dimensions across all your metrics. Use **`PushSing
378386
});
379387
...
380388
```
389+
390+
## Testing your code
391+
392+
### Environment variables
393+
394+
???+ tip
395+
Ignore this section, if:
396+
397+
* You are explicitly setting namespace/default dimension via `namespace` and `service` parameters
398+
* You're not instantiating `Metrics` in the global namespace
399+
400+
For example, `Metrics(namespace="ExampleApplication", service="booking")`
401+
402+
Make sure to set `POWERTOOLS_METRICS_NAMESPACE` and `POWERTOOLS_SERVICE_NAME` before running your tests to prevent failing on `SchemaValidation` exception. You can set it before you run tests by adding the environment variable.
403+
404+
```csharp title="Injecting Metric Namespace before running tests"
405+
Environment.SetEnvironmentVariable("POWERTOOLS_METRICS_NAMESPACE","AWSLambdaPowertools");
406+
```

docs/core/tracing.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ a provides functionality to reduce the overhead of performing common tracing tas
1010

1111
## Key Features
1212

13-
* Helper methods to improve the developer experience for creating [custom AWS X-Ray subsegments](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-subsegments.html).
13+
* Helper methods to improve the developer experience for creating [custom AWS X-Ray subsegments](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-subsegments.html){target=blank}.
1414
* Capture cold start as annotation.
1515
* Capture function responses and full exceptions as metadata.
1616
* Better experience when developing with multiple threads.
1717
* Auto-patch supported modules by AWS X-Ray
1818

19+
## Installation
20+
21+
Powertools are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*){target="_blank"} or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available.
22+
23+
* [AWS.Lambda.Powertools.Tracing](https://www.nuget.org/packages?q=AWS.Lambda.Powertools.Tracing):
24+
25+
`dotnet nuget add AWS.Lambda.Powertools.Tracing`
26+
1927
## Getting Started
2028

2129
Before you use this utility, your AWS Lambda function [must have permissions](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html#services-xray-permissions) to send traces to AWS X-Ray.

docs/utilities/parameters.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ title: Parameters
33
description: Utility
44
---
55

6+
???+ warning
7+
**This utility is currently in developer preview** and is intended strictly for feedback and testing purposes **and not for production workloads**. The version and all future versions tagged with the `-preview` suffix should be treated as not stable. Until this utility is [General Availability](https://github.com/awslabs/aws-lambda-powertools-dotnet/milestone/2) we may introduce significant breaking changes and improvements in response to customers feedback.
8+
69
<!-- markdownlint-disable MD013 -->
7-
The parameters utility provides high-level functions to retrieve one or multiple parameter values from [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html){target="_blank"}, [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/){target="_blank"}, [Amazon DynamoDB](https://aws.amazon.com/dynamodb/){target="_blank"}, or bring your own.
10+
The Parameters utility provides high-level functionality to retrieve one or multiple parameter values from [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html){target="_blank"}, [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/){target="_blank"}, or [Amazon DynamoDB](https://aws.amazon.com/dynamodb/){target="_blank"}. We also provide extensibility to bring your own providers.
811

912
## Key features
1013

1114
* Retrieve one or multiple parameters from the underlying provider
1215
* Cache parameter values for a given amount of time (defaults to 5 seconds)
1316
* Transform parameter values from JSON or base 64 encoded strings
14-
* Bring Your Own Parameter Store Provider
17+
* Bring your own parameter store provider
1518

16-
## Install
19+
## Installation
1720

18-
Powertools are available as NuGet packages. You can install the packages from NuGet gallery or from Visual Studio editor. Search `AWS.Lambda.Powertools*` to see various utilities available.
21+
Powertools are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*){target="_blank"} or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available.
1922

2023
* [AWS.Lambda.Powertools.Parameters](https://www.nuget.org/packages?q=AWS.Lambda.Powertools.Parameters):
2124

@@ -35,8 +38,8 @@ DynamoDB | `DynamoDBProvider.GetMultiple(string)` `DynamoDBProvider.GetMultiple<
3538

3639
## SSM Parameter Store
3740

38-
You can retrieve a single parameter using SsmProvider.Get() and pass the key of the parameter.
39-
For multiple parameters, you can use SsmProvider.GetMultiple() and pass the path to retrieve them all.
41+
You can retrieve a single parameter using `SsmProvider.Get()` and pass the key of the parameter.
42+
For multiple parameters, you can use `SsmProvider.GetMultiple()` and pass the path to retrieve them all.
4043

4144
Alternatively, you can retrieve the instance of provider and configure its underlying SDK client,
4245
in order to get data from other regions or use specific credentials.
@@ -179,10 +182,9 @@ For secrets stored in Secrets Manager, use `SecretsProvider`.
179182
Alternatively, you can retrieve the instance of provider and configure its underlying SDK client,
180183
in order to get data from other regions or use specific credentials.
181184

182-
183185
=== "SecretsProvider"
184186

185-
```c# hl_lines="13-15"
187+
```c# hl_lines="13-15"
186188
using AWS.Lambda.Powertools.Parameters;
187189
using AWS.Lambda.Powertools.Parameters.SecretsManager;
188190

@@ -224,7 +226,7 @@ in order to get data from other regions or use specific credentials.
224226
}
225227
```
226228

227-
=== "SecretsProvider with a custom clieent"
229+
=== "SecretsProvider with a custom client"
228230

229231
```c# hl_lines="11 14 15"
230232
using Amazon.SecretsManager;
@@ -263,16 +265,15 @@ For single parameters, you must use `id` as the [partition key](https://docs.aws
263265

264266
DynamoDB table with `id` partition key and `value` as attribute
265267

266-
| id | value |
267-
| ------------ | -------- |
268-
| my-parameter | my-value |
269-
270-
With this table, `DynamoDBProvider.Get("my-param")` will return `my-value`.
268+
| id | value |
269+
| ------------ | -------- |
270+
| my-parameter | my-value |
271271

272+
With this table, `DynamoDBProvider.Get("my-param")` will return `my-value`.
272273

273274
=== "DynamoDBProvider"
274275

275-
```c# hl_lines="10 11 14-16"
276+
```c# hl_lines="10 11 14-16"
276277
using AWS.Lambda.Powertools.Parameters;
277278
using AWS.Lambda.Powertools.Parameters.DynamoDB;
278279

@@ -301,17 +302,17 @@ You can retrieve multiple parameters sharing the same `id` by having a sort key
301302

302303
DynamoDB table with `id` primary key, `sk` as sort key` and `value` as attribute
303304

304-
| id | sk | value |
305-
| ----------- | ------- | ---------- |
306-
| my-hash-key | param-a | my-value-a |
307-
| my-hash-key | param-b | my-value-b |
308-
| my-hash-key | param-c | my-value-c |
305+
| id | sk | value |
306+
| ----------- | ------- | ---------- |
307+
| my-hash-key | param-a | my-value-a |
308+
| my-hash-key | param-b | my-value-b |
309+
| my-hash-key | param-c | my-value-c |
309310

310-
With this table, `DynamoDBProvider.GetMultiple("my-hash-key")` will return a dictionary response in the shape of `sk:value`.
311+
With this table, `DynamoDBProvider.GetMultiple("my-hash-key")` will return a dictionary response in the shape of `sk:value`.
311312

312313
=== "DynamoDBProvider"
313314

314-
```c# hl_lines="10 11 14-16"
315+
```c# hl_lines="10 11 14-16"
315316
using AWS.Lambda.Powertools.Parameters;
316317
using AWS.Lambda.Powertools.Parameters.DynamoDB;
317318

@@ -354,7 +355,7 @@ DynamoDB provider can be customized at initialization to match your table struct
354355

355356
=== "DynamoDBProvider"
356357

357-
```c# hl_lines="10-17"
358+
```c# hl_lines="10-17"
358359
using AWS.Lambda.Powertools.Parameters;
359360
using AWS.Lambda.Powertools.Parameters.DynamoDB;
360361

@@ -383,7 +384,7 @@ DynamoDB provider can be customized at initialization to match your table struct
383384
By default, all parameters and their corresponding values are cached for 5 seconds.
384385

385386
You can customize this default value using `DefaultMaxAge`. You can also customize this value for each parameter using
386-
`WithMaxAge`.
387+
`WithMaxAge`.
387388

388389
If you'd like to always ensure you fetch the latest parameter from the store regardless if already available in cache, use `ForceFetch`.
389390

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# AWS.Lambda.Powertools.Parameters
2+
3+
The Parameters utility provides high-level functionality to retrieve one or multiple parameter values from [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html), [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/), or [Amazon DynamoDB](https://aws.amazon.com/dynamodb/). Or bring your own providers.
4+
5+
## Key features
6+
7+
* Retrieve one or multiple parameters from the underlying provider
8+
* Cache parameter values for a given amount of time (defaults to 5 seconds)
9+
* Transform parameter values from JSON or base 64 encoded strings
10+
* Bring your own parameter store provider
11+
12+
## Read the docs
13+
14+
For a full list of features go to [awslabs.github.io/aws-lambda-powertools-dotnet/utilities/parameters/](awslabs.github.io/aws-lambda-powertools-dotnet/utilities/parameters/)
15+
16+
GitHub: <https://github.com/awslabs/aws-lambda-powertools-dotnet/>
17+
18+
## Sample Function using AWS Systems Manager Parameter Store
19+
20+
```csharp
21+
using AWS.Lambda.Powertools.Logging;
22+
using AWS.Lambda.Powertools.Parameters;
23+
using AWS.Lambda.Powertools.Parameters.SimpleSystemsManagement;
24+
25+
namespace HelloWorld;
26+
27+
public class Function
28+
{
29+
[Logging(LogEvent = true)]
30+
public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest apigwProxyEvent,
31+
ILambdaContext context)
32+
{
33+
// Get SSM Provider instance
34+
ISsmProvider ssmProvider = ParametersManager.SsmProvider;
35+
36+
// Retrieve a single parameter
37+
string? value = await ssmProvider
38+
.GetAsync("/my/parameter")
39+
.ConfigureAwait(false);
40+
41+
// Retrieve multiple parameters from a path prefix
42+
// This returns a Dictionary with the parameter name as key
43+
IDictionary<string, string?> values = await ssmProvider
44+
.GetMultipleAsync("/my/path/prefix")
45+
.ConfigureAwait(false);
46+
47+
...
48+
49+
}
50+
}
51+
```

0 commit comments

Comments
 (0)