@@ -0,0 +1,2556 @@
+//snippet-sourcedescription:%5BCreateAPIKeys.java demonstrates how to create Api keys.%5D%0A//snippet-keyword:%5BSDK for Java v2%5D%0A//snippet-keyword:%5BCode Sample%5D%0A//snippet-service:%5BAmazon API Gateway%5D%0A//snippet-sourcetype:%5Bfull-example%5D%0A//snippet-sourcedate:%5B12/16/2021%5D%0A//snippet-sourceauthor:%5Bscmacdon - aws%5D%0A%0A/*%0A   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.%0A   SPDX-License-Identifier: Apache-2.0%0A*/%0A%0Apackage com.example.gateway;%0A%0A// snippet-start:%5Bapigateway.java2.createapikeys.import%5D%0Aimport software.amazon.awssdk.regions.Region;%0Aimport software.amazon.awssdk.services.apigateway.ApiGatewayClient;%0Aimport software.amazon.awssdk.services.apigateway.model.*;%0A// snippet-end:%5Bapigateway.java2.createapikeys.import%5D%0A%0A/**%0A * To run this Java V2 code example, ensure that you have setup your development environment, including your credentials.%0A *%0A * For information, see this documentation topic:%0A *%0A * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html%0A */%0A%0Apublic class CreateAPIKey %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        Region region = Region.US_EAST_1;%0A        ApiGatewayClient apiGateway = ApiGatewayClient.builder()%0A                .region(region)%0A                .build();%0A%0A        createApiKey(apiGateway,%22accessKey%22, %22secretKey%22);%0A        apiGateway.close();%0A    %7D%0A%0A    // snippet-start:%5Bapigateway.java2.createapikeys.main%5D%0A    public static void createApiKey(ApiGatewayClient apiGateway, String accessKey, String secretKey) %7B%0A%0A        try %7B%0A%0A            CreateApiKeyRequest apiKeyRequest = CreateApiKeyRequest.builder()%0A                    .name(%22Key Name%22)%0A                    .description(%22Key description%22)%0A                    .enabled(true)%0A                    .generateDistinctId(true)%0A                    .build();%0A%0A            //Creating a api key%0A            CreateApiKeyResponse response = apiGateway.createApiKey(apiKeyRequest);%0A         /*%0A          If we have a plan for the api keys, we can set it for the created api key.%0A         */%0A            CreateUsagePlanKeyRequest planRequest = CreateUsagePlanKeyRequest.builder()%0A                    .usagePlanId(%22q18zxs%22)%0A                    .keyId(response.id())%0A                    .keyType(%22API_KEY%22)%0A                    .build();%0A%0A            apiGateway.createUsagePlanKey(planRequest);%0A            apiGateway.close();%0A%0A        %7D catch (ApiGatewayException e) %7B%0A          System.err.println(e.awsErrorDetails().errorMessage());%0A          System.exit(1);%0A    %7D%0A%7D%0A// snippet-end:%5Bapigateway.java2.createapikeys.main%5D%0A%7D%0A

Create CreateAPIKey.java