Skip to content

Commit fa76593

Browse files
authored
Merge pull request #559 from amirkaws/add-configuration-parameter-provider
feat: Add AppConfig parameter provider
2 parents 6286cad + 5b078ed commit fa76593

14 files changed

+2930
-6
lines changed

docs/utilities/parameters.md

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Utility
44
---
55

66
<!-- markdownlint-disable MD013 -->
7-
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.
7+
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"}, [Amazon DynamoDB](https://aws.amazon.com/dynamodb/){target="_blank"}, or [AWS AppConfig](https://docs.aws.amazon.com/appconfig/latest/userguide/what-is-appconfig.html){target="_blank"}. We also provide extensibility to bring your own providers.
88

99
## Key features
1010

@@ -33,6 +33,7 @@ This utility requires additional permissions to work as expected. See the table
3333
| Secrets Manager | `SecretsProvider.Get(string)` `SecretsProvider.Get<T>(string)` | `secretsmanager:GetSecretValue` |
3434
| DynamoDB | `DynamoDBProvider.Get(string)` `DynamoDBProvider.Get<T>(string)` | `dynamodb:GetItem` |
3535
| DynamoDB | `DynamoDBProvider.GetMultiple(string)` `DynamoDBProvider.GetMultiple<T>(string)` | `dynamodb:Query` |
36+
| App Config | `AppConfigProvider.Get()` | `appconfig:StartConfigurationSession` `appconfig:GetLatestConfiguration` |
3637

3738
## SSM Parameter Store
3839

@@ -341,6 +342,7 @@ You can retrieve multiple parameters sharing the same `id` by having a sort key
341342
"param-b": "my-value-b",
342343
"param-c": "my-value-c"
343344
}
345+
```
344346

345347
**Customizing DynamoDBProvider**
346348

@@ -377,6 +379,106 @@ DynamoDB provider can be customized at initialization to match your table struct
377379
}
378380
```
379381

382+
## App Configurations
383+
384+
For application configurations in AWS AppConfig, use `AppConfigProvider`.
385+
386+
Alternatively, you can retrieve the instance of provider and configure its underlying SDK client,
387+
in order to get data from other regions or use specific credentials.
388+
389+
=== "AppConfigProvider"
390+
391+
```c# hl_lines="10-13 16-18"
392+
using AWS.Lambda.Powertools.Parameters;
393+
using AWS.Lambda.Powertools.Parameters.AppConfig;
394+
395+
public class Function
396+
{
397+
public async Task<APIGatewayProxyResponse> FunctionHandler
398+
(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
399+
{
400+
// Get AppConfig Provider instance
401+
IAppConfigProvider appConfigProvider = ParametersManager.AppConfigProvider
402+
.DefaultApplication("MyApplicationId")
403+
.DefaultEnvironment("MyEnvironmentId")
404+
.DefaultConfigProfile("MyConfigProfileId");
405+
406+
// Retrieve a single configuration, latest version
407+
IDictionary<string, string?> value = await appConfigProvider
408+
.GetAsync()
409+
.ConfigureAwait(false);
410+
}
411+
}
412+
```
413+
414+
=== "AppConfigProvider with an explicit region"
415+
416+
```c# hl_lines="10-14"
417+
using AWS.Lambda.Powertools.Parameters;
418+
using AWS.Lambda.Powertools.Parameters.AppConfig;
419+
420+
public class Function
421+
{
422+
public async Task<APIGatewayProxyResponse> FunctionHandler
423+
(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
424+
{
425+
// Get AppConfig Provider instance
426+
IAppConfigProvider appConfigProvider = ParametersManager.AppConfigProvider
427+
.ConfigureClient(RegionEndpoint.EUCentral1)
428+
.DefaultApplication("MyApplicationId")
429+
.DefaultEnvironment("MyEnvironmentId")
430+
.DefaultConfigProfile("MyConfigProfileId");
431+
432+
// Retrieve a single configuration, latest version
433+
IDictionary<string, string?> value = await appConfigProvider
434+
.GetAsync()
435+
.ConfigureAwait(false);
436+
}
437+
}
438+
```
439+
440+
**Using AWS AppConfig Feature Flags**
441+
442+
Feature flagging is a powerful tool that allows safely pushing out new features in a measured and usually gradual way. AppConfig provider offers helper methods to make it easier to work with feature flags.
443+
444+
=== "AppConfigProvider"
445+
446+
```c# hl_lines="10-13 16-18 23-25"
447+
using AWS.Lambda.Powertools.Parameters;
448+
using AWS.Lambda.Powertools.Parameters.AppConfig;
449+
450+
public class Function
451+
{
452+
public async Task<APIGatewayProxyResponse> FunctionHandler
453+
(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
454+
{
455+
// Get AppConfig Provider instance
456+
IAppConfigProvider appConfigProvider = ParametersManager.AppConfigProvider
457+
.DefaultApplication("MyApplicationId")
458+
.DefaultEnvironment("MyEnvironmentId")
459+
.DefaultConfigProfile("MyConfigProfileId");
460+
461+
// Check if feature flag is enabled
462+
var isFeatureFlagEnabled = await appConfigProvider
463+
.IsFeatureFlagEnabledAsync("MyFeatureFlag")
464+
.ConfigureAwait(false);
465+
466+
if (isFeatureFlagEnabled)
467+
{
468+
// Retrieve an attribute value of the feature flag
469+
var strAttValue = await appConfigProvider
470+
.GetFeatureFlagAttributeValueAsync<string>("MyFeatureFlag", "StringAttribute")
471+
.ConfigureAwait(false);
472+
473+
// Retrieve another attribute value of the feature flag
474+
var numberAttValue = await appConfigProvider
475+
.GetFeatureFlagAttributeValueAsync<int>("MyFeatureFlag", "NumberAttribute")
476+
.ConfigureAwait(false);
477+
}
478+
}
479+
}
480+
```
481+
380482
## Advanced configuration
381483

382484
### Caching

libraries/src/AWS.Lambda.Powertools.Parameters/AWS.Lambda.Powertools.Parameters.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
<ItemGroup>
1414
<!-- Package versions are Centrally managed in Directory.Packages.props file -->
1515
<!-- More info https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management -->
16-
<PackageReference Include="AWSSDK.DynamoDBv2"/>
17-
<PackageReference Include="AWSSDK.SecretsManager"/>
18-
<PackageReference Include="AWSSDK.SimpleSystemsManagement"/>
19-
<PackageReference Include="Microsoft.Extensions.Configuration"/>
16+
<PackageReference Include="AWSSDK.AppConfig" />
17+
<PackageReference Include="AWSSDK.AppConfigData" />
18+
<PackageReference Include="AWSSDK.DynamoDBv2" />
19+
<PackageReference Include="AWSSDK.SecretsManager" />
20+
<PackageReference Include="AWSSDK.SimpleSystemsManagement" />
21+
<PackageReference Include="Microsoft.Extensions.Configuration" />
2022
<ProjectReference Include="..\AWS.Lambda.Powertools.Common\AWS.Lambda.Powertools.Common.csproj" PrivateAssets="All" />
2123
</ItemGroup>
2224

0 commit comments

Comments
 (0)