Use DescribeForecast with an AWS SDK - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use DescribeForecast with an AWS SDK

The following code example shows how to use DescribeForecast.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.forecast.ForecastClient; import software.amazon.awssdk.services.forecast.model.DescribeForecastRequest; import software.amazon.awssdk.services.forecast.model.DescribeForecastResponse; import software.amazon.awssdk.services.forecast.model.ForecastException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DescribeForecast { public static void main(String[] args) { final String usage = """ Usage: <forecastarn>\s Where: forecastarn - The arn of the forecast (for example, "arn:aws:forecast:us-west-2:xxxxx322:forecast/my_forecast) """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String forecastarn = args[0]; Region region = Region.US_WEST_2; ForecastClient forecast = ForecastClient.builder() .region(region) .build(); describe(forecast, forecastarn); forecast.close(); } public static void describe(ForecastClient forecast, String forecastarn) { try { DescribeForecastRequest request = DescribeForecastRequest.builder() .forecastArn(forecastarn) .build(); DescribeForecastResponse response = forecast.describeForecast(request); System.out.println("The name of the forecast is " + response.forecastName()); } catch (ForecastException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }