@@ -0,0 +1,3176 @@
+//snippet-sourcedescription:%5BCreateSecret.java demonstrates how to create a secret for AWS Secrets Manager.%5D%0A//snippet-keyword:%5BJava%5D%0A//snippet-keyword:%5BCode Sample%5D%0A//snippet-keyword:%5BAWS Secrets Manager%5D%0A//snippet-service:%5BAWS Secrets Manager%5D%0A//snippet-sourcetype:%5Bfull-example%5D%0A//snippet-sourcedate:%5B9/3/2020%5D%0A//snippet-sourceauthor:%5Bscmacdon AWS%5D%0A/*%0A * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22).%0A * You may not use this file except in compliance with the License.%0A * A copy of the License is located at%0A *%0A *  http://aws.amazon.com/apache2.0%0A *%0A * or in the %22license%22 file accompanying this file. This file is distributed%0A * on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either%0A * express or implied. See the License for the specific language governing%0A * permissions and limitations under the License.%0A */%0A%0Apackage com.example.secrets;%0A%0A//snippet-start:%5Bsecretsmanager.java2.create_secret.import%5D%0Aimport software.amazon.awssdk.regions.Region;%0Aimport software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;%0Aimport software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest;%0Aimport software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse;%0Aimport software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException;%0A//snippet-end:%5Bsecretsmanager.java2.create_secret.import%5D%0A%0Apublic class CreateSecret %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        final String USAGE = %22%5Cn%22 +%0A                %22To run this example, supply the name of the secret (ie, tutorials/MyFirstSecret), and the secret value.  %5Cn%22 +%0A                %22%5Cn%22 +%0A                %22Ex: GetSecretValue %3CsecretName%3E%3CsecretValue%3E%5Cn%22;%0A%0A        if (args.length %3C 2) %7B%0A            System.out.println(USAGE);%0A            System.exit(1);%0A        %7D%0A%0A        /* Read the name from command args */%0A        String secretName = args%5B0%5D;%0A        String secretValue= args%5B1%5D;%0A%0A        Region region = Region.US_EAST_1;%0A        SecretsManagerClient secretsClient = SecretsManagerClient.builder()%0A                .region(region)%0A                .build();%0A%0A       String secretARN = createNewSecret(secretsClient, secretName, secretValue);%0A       System.out.println(%22The secret ARN is %22+ secretARN);%0A    %7D%0A%0A    //snippet-start:%5Bsecretsmanager.java2.create_secret.main%5D%0A    public static String createNewSecret( SecretsManagerClient secretsClient, String secretName, String secretValue) %7B%0A%0A        try %7B%0A            CreateSecretRequest secretRequest = CreateSecretRequest.builder()%0A                .name(secretName)%0A                .description(%22This secret was created by the AWS Secret Manager Java API%22)%0A                .secretString(secretValue)%0A                .build();%0A%0A            CreateSecretResponse secretResponse = secretsClient.createSecret(secretRequest);%0A            return secretResponse.arn();%0A%0A        %7D catch (SecretsManagerException e) %7B%0A            System.err.println(e.awsErrorDetails().errorMessage());%0A            System.exit(1);%0A        %7D%0A        return %22%22;%0A    %7D%0A    //snippet-end:%5Bsecretsmanager.java2.create_secret.main%5D%0A%7D%0A

Create CreateSecret.java