AppConfig usage with AWS Java SDK v2

1

Hello,

The Java SDK for AppConfig changed between versions v1 and v2. Dependencies below:

  • v1: com.amazonaws:aws-java-sdk-appconfig:1.12.257
  • v2: software.amazon.awssdk:appconfig (needs platform("software.amazon .awssdk:bom:2.17.228")

The question is: how to fetch an AppConfig configuration profile value from Java using the v2 API? Is there a code example available?

I was able to find a code example about how to use the v1 API: https://stackoverflow.com/questions/63751913/amazon-appconfig-from-spring-boot

However, I am unable to find a code example for the same purpose for the v2 API.

I have some partial progress:

  • This will provide the AWS AppConfig client:
    public AppConfigClient buildV2() {
        return AppConfigClient.create();
    }
  • This will call AppConfig to get a configuration profile response:
    private GetConfigurationProfileResponse fetchConfigurationResult(ConfigurationProfiles.Key configurationProfileKey) {
        GetConfigurationProfileRequest request = GetConfigurationProfileRequest.builder()
            .applicationId(application)
            // environment?
            .configurationProfileId(profileName)
            .build();

        GetConfigurationProfileResponse response = appConfigClient.getConfigurationProfile(request);

        return response;
    }

What I don't know are:

  • How to pass the AppConfig environment to the GetConfigurationProfileRequest instance
  • I understand I have to get an AppConfig token between the calls tp create and fetchConfigurationResult. How to use the v2 API to get that token?
  • After getting the GetConfigurationProfileResponse instance, how to use it for getting the actual configuration profile value? The v1 API has some methods in the GetConfigurationResult class like getContentType and getContent

Thanks

質問済み 2年前3406ビュー
1回答
1

Hello,

One should be looking at the appconfigdata package rather than the appconfig package. This contains the two data plane APIs (StartConfigurationSession and GetLatestConfiguration) that can be used to fetch deployed configuration.

More information here using CLI (which can be converted into your desired SDK code) - https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-retrieving-the-configuration.html

Here's an example in Java on how you can go about integrating with our data plane.

  • Example of how to start a session -
String sessionToken = client.startConfigurationSession(
                StartConfigurationSessionRequest.builder()
                        .applicationIdentifier("some application name")
                        .environmentIdentifier("some environment name")
                        .configurationProfileIdentifier("some config profile name")
                        .build()).initialConfigurationToken();
  • and call to get latest configuration using that initial token -
while(true) {
GetLatestConfigurationResponse getLatestConfigurationResponse = client.getLatestConfiguration(
                    GetLatestConfigurationRequest.builder()
                            .configurationToken(sessionToken)
                            .build());

if(getLatestConfigurationResponse.content().asByteArray().size > 0) {
 // Content returned, do something with it
}

// Need to re-assign the next token returned
sessionToken = getLatestConfigurationResponse.nextPollConfigurationToken();

// Sleep for 15 seconds
Thread.sleep(15_000);
}

I hope the above shared information is insightful to your query. In case if you have any questions regarding the AWS Java SDK, you can directly reach the Dev team by pulling an issue on the Github [2]. Also, in case if you have any question regarding the AWS AppConfig service itself, which is a capability of AWS Systems Manager, please feel free to create a support ticket with our premium support team.

References:

[1] https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-retrieving-the-configuration.html

[2] https://github.com/aws/aws-sdk-java/issues

profile pictureAWS
サポートエンジニア
Yash_C
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ