|
| 1 | +// This file is referenced by docs/utilities/parameters.md |
| 2 | +// via pymdownx.snippets (mkdocs). |
| 3 | + |
| 4 | +namespace AWS.Lambda.Powertools.Docs.Snippets.Parameters; |
| 5 | + |
| 6 | +// --8<-- [start:app_config_provider] |
| 7 | +using AWS.Lambda.Powertools.Parameters; |
| 8 | +using AWS.Lambda.Powertools.Parameters.AppConfig; |
| 9 | + |
| 10 | +public class Function |
| 11 | +{ |
| 12 | + public async Task<APIGatewayProxyResponse> FunctionHandler |
| 13 | + (APIGatewayProxyRequest apigProxyEvent, ILambdaContext context) |
| 14 | + { |
| 15 | + // Get AppConfig Provider instance |
| 16 | + IAppConfigProvider appConfigProvider = ParametersManager.AppConfigProvider |
| 17 | + .DefaultApplication("MyApplicationId") |
| 18 | + .DefaultEnvironment("MyEnvironmentId") |
| 19 | + .DefaultConfigProfile("MyConfigProfileId"); |
| 20 | + |
| 21 | + // Retrieve a single configuration, latest version |
| 22 | + IDictionary<string, string?> value = await appConfigProvider |
| 23 | + .GetAsync() |
| 24 | + .ConfigureAwait(false); |
| 25 | + } |
| 26 | +} |
| 27 | +// --8<-- [end:app_config_provider] |
| 28 | + |
| 29 | +// --8<-- [start:app_config_provider_explicit_region] |
| 30 | +using AWS.Lambda.Powertools.Parameters; |
| 31 | +using AWS.Lambda.Powertools.Parameters.AppConfig; |
| 32 | + |
| 33 | +public class Function |
| 34 | +{ |
| 35 | + public async Task<APIGatewayProxyResponse> FunctionHandler |
| 36 | + (APIGatewayProxyRequest apigProxyEvent, ILambdaContext context) |
| 37 | + { |
| 38 | + // Get AppConfig Provider instance |
| 39 | + IAppConfigProvider appConfigProvider = ParametersManager.AppConfigProvider |
| 40 | + .ConfigureClient(RegionEndpoint.EUCentral1) |
| 41 | + .DefaultApplication("MyApplicationId") |
| 42 | + .DefaultEnvironment("MyEnvironmentId") |
| 43 | + .DefaultConfigProfile("MyConfigProfileId"); |
| 44 | + |
| 45 | + // Retrieve a single configuration, latest version |
| 46 | + IDictionary<string, string?> value = await appConfigProvider |
| 47 | + .GetAsync() |
| 48 | + .ConfigureAwait(false); |
| 49 | + } |
| 50 | +} |
| 51 | +// --8<-- [end:app_config_provider_explicit_region] |
| 52 | + |
| 53 | +// --8<-- [start:app_config_feature_flags] |
| 54 | +using AWS.Lambda.Powertools.Parameters; |
| 55 | +using AWS.Lambda.Powertools.Parameters.AppConfig; |
| 56 | + |
| 57 | +public class Function |
| 58 | +{ |
| 59 | + public async Task<APIGatewayProxyResponse> FunctionHandler |
| 60 | + (APIGatewayProxyRequest apigProxyEvent, ILambdaContext context) |
| 61 | + { |
| 62 | + // Get AppConfig Provider instance |
| 63 | + IAppConfigProvider appConfigProvider = ParametersManager.AppConfigProvider |
| 64 | + .DefaultApplication("MyApplicationId") |
| 65 | + .DefaultEnvironment("MyEnvironmentId") |
| 66 | + .DefaultConfigProfile("MyConfigProfileId"); |
| 67 | + |
| 68 | + // Check if feature flag is enabled |
| 69 | + var isFeatureFlagEnabled = await appConfigProvider |
| 70 | + .IsFeatureFlagEnabledAsync("MyFeatureFlag") |
| 71 | + .ConfigureAwait(false); |
| 72 | + |
| 73 | + if (isFeatureFlagEnabled) |
| 74 | + { |
| 75 | + // Retrieve an attribute value of the feature flag |
| 76 | + var strAttValue = await appConfigProvider |
| 77 | + .GetFeatureFlagAttributeValueAsync<string>("MyFeatureFlag", "StringAttribute") |
| 78 | + .ConfigureAwait(false); |
| 79 | + |
| 80 | + // Retrieve another attribute value of the feature flag |
| 81 | + var numberAttValue = await appConfigProvider |
| 82 | + .GetFeatureFlagAttributeValueAsync<int>("MyFeatureFlag", "NumberAttribute") |
| 83 | + .ConfigureAwait(false); |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +// --8<-- [end:app_config_feature_flags] |
0 commit comments