AWS AppConfig エージェントを使用してバリアントを含む機能フラグを取得する - AWS AppConfig

AWS AppConfig エージェントを使用してバリアントを含む機能フラグを取得する

次の各サンプルには、コードによって実行されるアクションに関するコメントが含まれています。

Java
public static void retrieveConfigFromAgentWithVariants() throws Exception { /* This sample retrieves feature flag configuration data containing variants from AWS AppConfig Agent. For more information about the agent, see How to use AWS AppConfig Agent */ // Make a GET request to the agent's local server to retrieve the configuration data URL url = new URL("http://localhost:2772/applications/MyDemoApp/environments/Beta/configurations/MyConfigProfile"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); // Provide context in the 'Context' header // In the header value, use '=' to separate context key from context value // Note: Multiple context values may be passed either across // multiple headers or as comma-separated values in a single header con.setRequestProperty("Context", "country=US"); StringBuilder content; try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) { content = new StringBuilder(); int ch; while ((ch = in.read()) != -1) { content.append((char) ch); } } con.disconnect(); System.out.println("Configuration from agent via HTTP: " + content); }
Python
# This sample retrieve features flag configuration data # containing variants from AWS AppConfig Agent. # For more information about the agent, see How to use AWS AppConfig Agent import requests application_name = 'MyDemoApp' environment_name = 'Beta' config_profile_name = 'MyConfigProfile' # make a GET request to the agent's local server to retrieve the configuration data response = requests.get(f"http://localhost:2772/applications/application_name/environments/environment_name/configurations/configuration_profile_name", headers = { "Context": "country=US" # Provide context in the 'Context' header # In the header value, use '=' to separate context key from context value # Note: Multiple context values may be passed either across # multiple headers or as comma-separated values in a single header } ) print("Configuration from agent via HTTP: ", response.json())
JavaScript
// This sample retrieves feature flag configuration data // containing variants from AWS AppConfig Agent. // For more information about the agent, see How to use AWS AppConfig Agent const application_name = "MyDemoApp"; const environment_name = "Beta"; const config_profile_name = "MyConfigProfile"; const url = `http://localhost:2772/applications/$application_name/environments/$environment_name/configurations/$configuration_profile_name`; // make a GET request to the agent's local server to retrieve the configuration data const response = await fetch(url, { method: 'GET', headers: { 'Context': 'country=US' // Provide context in the 'Context' header // In the header value, use '=' to separate context key from context value // Note: Multiple context values may be passed either across // multiple headers or as comma-separated values in a single header } }); const config = await response.json(); console.log("Configuration from agent via HTTP: ", config);