Java Code Examples for software.amazon.awssdk.regions.Region#US_WEST_2

The following examples show how to use software.amazon.awssdk.regions.Region#US_WEST_2 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetObjectTags.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

         if (args.length < 2) {
              System.out.println("Please specify a bucket name and key name");
              System.exit(1);
          }

        String bucketName = args[0];
        String keyName = args[1];

        Region region = Region.US_WEST_2;
        S3Client s3 = S3Client.builder()
                .region(region)
                .build();

        listTags(s3,bucketName,keyName );
    }
 
Example 2
Source File: RebootInstance.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    final String USAGE =
            "To run this example, supply an instance id\n" +
                    "Ex: RebootInstance <instance_id>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String instanceId = args[0];

    //Create an Ec2Client object
    Region region = Region.US_WEST_2;
    Ec2Client ec2 = Ec2Client.builder()
            .region(region)
            .build();

    rebootEC2Instance(ec2, instanceId);
}
 
Example 3
Source File: UpdateTable.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage:\n" +
            "    UpdateTable <table> <read> <write>\n\n" +
            "Where:\n" +
            "    table - the table to put the item in (i.e., Music3)\n" +
            "    read  - the new read capacity of the table (i.e., 16)\n" +
            "    write - the new write capacity of the table (i.e., 10)\n\n" +
            "Example:\n" +
            "    UpdateTable Music3 16 10\n";

    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String tableName = args[0];
    Long readCapacity = Long.parseLong(args[1]);
    Long writeCapacity = Long.parseLong(args[2]);

    // Create the DynamoDbClient object
    Region region = Region.US_WEST_2;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();

    updateDynamoDBTable(ddb, tableName, readCapacity, writeCapacity);
}
 
Example 4
Source File: ListDataSetGroups.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    // Create a Forecast client
    Region region = Region.US_WEST_2;
    ForecastClient forecast = ForecastClient.builder()
            .region(region)
            .build();

        listDataGroups(forecast);
}
 
Example 5
Source File: DeleteItem.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        final String USAGE = "\n" +
                "Usage:\n" +
                "    DeleteItem <table> <key> <keyval>\n\n" +
                "Where:\n" +
                "    table - the table to delete the item from (i.e., Music3)\n" +
                "    key -  the key used in the table (i.e., Artist) \n" +
                "    keyval  - the key value that represents the item to delete (i.e., Famous Band)\n" +
                "Example:\n" +
                "    Music3 Artist Famous Band\n\n" +
                "**Warning** This program will actually delete the item\n" +
                "            that you specify!\n";

        if (args.length < 3) {
            System.out.println(USAGE);
            System.exit(1);
        }

        /* Read the name from command args */
        String tableName = args[0];
        String key = args[1];
        String keyVal = args[2];

        System.out.format("Deleting item \"%s\" from %s\n", keyVal, tableName);

        // Create the DynamoDbClient object
        Region region = Region.US_WEST_2;
        DynamoDbClient ddb = DynamoDbClient.builder()
                .region(region)
                .build();

        // Delete an item
        deleteDymamoDBItem(ddb, tableName, key, keyVal);
    }
 
Example 6
Source File: DescribeAddresses.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        //Create an Ec2Client object
        Region region = Region.US_WEST_2;
        Ec2Client ec2 = Ec2Client.builder()
                .region(region)
                .build();

        describeEC2Address(ec2 );
    }
 
Example 7
Source File: AmazonS3ServiceIntegrationTest.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void setUp() throws IOException {

    // Run tests on Real AWS Resources
    region = Region.US_WEST_2;
    s3 = S3Client.builder().region(region).build();
    try (InputStream input = AmazonS3ServiceIntegrationTest.class.getClassLoader().getResourceAsStream("config.properties")) {

        Properties prop = new Properties();

        if (input == null) {
            System.out.println("Sorry, unable to find config.properties");
            return;
        }

        //load a properties file from class path, inside static method
        prop.load(input);

        // Populate the data members required for all tests
        bucketName = prop.getProperty("bucketName");
        objectKey = prop.getProperty("objectKey");
        objectPath= prop.getProperty("objectPath");
        toBucket = prop.getProperty("toBucket");
        policyText = prop.getProperty("policyText");
        id  = prop.getProperty("id");
        access  = prop.getProperty("access");

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
Example 8
Source File: PutObject.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage:\n" +
            "  PutObject <bucket> <object> <path> \n\n" +
            "Where:\n" +
            "  bucket - the bucket to upload an object into\n" +
            "  object - the object to upload (ie, book.pdf)\n" +
            "  path -  the path where the file is located (C:/AWS/book2.pdf) \n\n" +
            "Examples:\n" +
            "    PutObject mybucket book.pdf C:/AWS/book2.pdf";

    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String bucketName = args[0];
    String objectKey = args[1];
    String objectPath = args[2];

    System.out.println("Putting object " + objectKey +" into bucket "+bucketName);
    System.out.println("  in bucket: " + bucketName);

    // Create the S3Client object
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder()
            .region(region)
            .build();

    String result = putS3Object(s3, bucketName, objectKey, objectPath);
    System.out.println("Tag information: "+result);
}
 
Example 9
Source File: GetAcl.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage: \n" +
            "  GetAcl <bucket> [object]\n\n" +
            "Where:\n" +
            "  bucket - the bucket to get the access control list (ACL) for\n" +
            "  object - (optional) the object to get the ACL for.\n" +
            "           If object is specified, the retrieved ACL will be\n" +
            "           for the object, not the bucket.\n\n" +
            "Examples:\n" +
            "    GetAcl  bucket1\n" +
            "    GetAcl  bucket1 book.pdf\n\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String bucketName = args[0];
    String objectKey = args[1];

    System.out.println("Retrieving ACL for object: " + objectKey);
    System.out.println("in bucket: " + bucketName);

    // Create the S3Client object
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder().region(region).build();
    getBucketACL(s3,objectKey,bucketName);

    System.out.println("Done!");
}
 
Example 10
Source File: ListMigrationTasks.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        Region region = Region.US_WEST_2;
        MigrationHubClient migrationClient = MigrationHubClient.builder()
                .region(region)
                .build();

        listMigrTasks(migrationClient) ;
   }
 
Example 11
Source File: DescribeKeyPairs.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        //Create an Ec2Client object
        Region region = Region.US_WEST_2;
        Ec2Client ec2 = Ec2Client.builder()
                .region(region)
                .build();

        describeEC2Keys(ec2);

    }
 
Example 12
Source File: CreateForecast.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        final String USAGE = "\n" +
                "Usage:\n" +
                "    CreateForecast <name><predictorArn> \n\n" +
                "Where:\n" +
                "    name - the name of the forecast \n\n" +
                "    predictorArn - the Amazon Resource Name (ARN) of the predictor to use \n\n" +
                "Example:\n" +
                "    CreateForecast MyForecast arn:aws:forecast:us-west-2:81454e33:predictor/MyPredictor\n";

        if (args.length < 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String name = args[0];
        String predictorArn = args[1];

        // Create a Forecast client
        Region region = Region.US_WEST_2;
        ForecastClient forecast = ForecastClient.builder()
                .region(region)
                .build();

        String forecastArn = createNewForecast(forecast, name, predictorArn) ;
        System.out.println("The ARN of the new forecast is "+forecastArn);
    }
 
Example 13
Source File: SetBucketPolicy.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage:\n" +
            "    SetBucketPolicy <bucket> [policyfile]\n\n" +
            "Where:\n" +
            "    bucket     - the bucket to set the policy on.\n" +
            "    policyfile - an optional JSON file containing the policy\n" +
            "                 description.\n\n" +
            "If no policyfile is given, a generic public-read policy will be set on\n" +
            "the bucket.\n\n" +
            "Example:\n" +
            "    SetBucketPolicy testbucket mypolicy.json\n\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String bucketName = args[0];
    String policyText = getBucketPolicyFromFile(args[1]);

    System.out.println("Setting policy:");
    System.out.println("----");
    System.out.println(policyText);
    System.out.println("----");
    System.out.format("On S3 bucket: \"%s\"\n", bucketName);

    // Create the S3Client object
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder()
            .region(region)
            .build();

    // Set the Bucket Policy
    setPolicy(s3, bucketName, policyText);
}
 
Example 14
Source File: ListObjects.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        if (args.length < 1) {
           System.out.println("Please specify a bucket name");
           System.exit(1);
         }

        String bucketName = args[0];
        Region region = Region.US_WEST_2;
        S3Client s3 = S3Client.builder()
                .region(region)
                .build();

        listBucketObjects(s3, bucketName);
    }
 
Example 15
Source File: S3BucketOps.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        // snippet-start:[s3.java2.s3_bucket_ops.create_bucket]
        // snippet-start:[s3.java2.s3_bucket_ops.region]
        Region region = Region.US_WEST_2;
        S3Client s3 = S3Client.builder().region(region).build();
        // snippet-end:[s3.java2.s3_bucket_ops.region]
        String bucket = "bucket" + System.currentTimeMillis();
        System.out.println(bucket);

        // Create bucket
        CreateBucketRequest createBucketRequest = CreateBucketRequest
                .builder()
                .bucket(bucket)
                .createBucketConfiguration(CreateBucketConfiguration.builder()
                        .locationConstraint(region.id())
                        .build())
                .build();
        s3.createBucket(createBucketRequest);
        // snippet-end:[s3.java2.s3_bucket_ops.create_bucket]

        // snippet-start:[s3.java2.s3_bucket_ops.list_bucket]
        // List buckets
        ListBucketsRequest listBucketsRequest = ListBucketsRequest.builder().build();
        ListBucketsResponse listBucketsResponse = s3.listBuckets(listBucketsRequest);
        listBucketsResponse.buckets().stream().forEach(x -> System.out.println(x.name()));
        // snippet-end:[s3.java2.s3_bucket_ops.list_bucket]

        // Delete empty bucket
        // snippet-start:[s3.java2.s3_bucket_ops.delete_bucket]      
        DeleteBucketRequest deleteBucketRequest = DeleteBucketRequest.builder().bucket(bucket).build();
        s3.deleteBucket(deleteBucketRequest);
        // snippet-end:[s3.java2.s3_bucket_ops.delete_bucket] 
    }
 
Example 16
Source File: GetSimpleSystemsManagementParas.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        // snippet-start:[ssm.Java2.get_params.main]
        SsmClient ssmClient;

        try {

            Region region = Region.US_WEST_2;
            ssmClient = SsmClient.builder().region(region).build();

            // Create a DescribeParametersRequest object
            DescribeParametersRequest desRequest = DescribeParametersRequest.builder()
                    .maxResults(10)
                    .build();

            // Get SSM Parameters (you can define them in the AWS Console)
            DescribeParametersResponse desResponse = ssmClient.describeParameters(desRequest);

            List<ParameterMetadata> params = desResponse.parameters();

            //Iterate through the list
            Iterator<ParameterMetadata> paramIterator = params.iterator();

            while(paramIterator.hasNext()) {

                ParameterMetadata paraMeta = (ParameterMetadata)paramIterator.next();

                System.out.println(paraMeta.name());
                System.out.println(paraMeta.description());
            }

        } catch (SsmException e) {
            e.getStackTrace();
        }
        // snippet-end:[ssm.Java2.get_params.main]
    }
 
Example 17
Source File: EventStreamAws4SignerTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * Verify that when an event stream is open from one day to the next, the signature is properly signed for the day of the
 * event.
 */
@Test
public void openStreamEventSignaturesCanRollOverBetweenDays() {
    EventStreamAws4Signer signer = EventStreamAws4Signer.create();

    Region region = Region.US_WEST_2;
    AwsCredentials credentials = AwsBasicCredentials.create("a", "s");
    String signingName = "name";
    AdjustableClock clock = new AdjustableClock();
    clock.time = Instant.parse("2020-01-01T23:59:59Z");

    SdkHttpFullRequest initialRequest = SdkHttpFullRequest.builder()
                                                          .uri(URI.create("http://localhost:8080"))
                                                          .method(SdkHttpMethod.GET)
                                                          .build();
    SdkHttpFullRequest signedRequest = SignerTestUtils.signRequest(signer, initialRequest, credentials, signingName, clock,
                                                                   region.id());

    ByteBuffer event = new Message(Collections.emptyMap(), "foo".getBytes(UTF_8)).toByteBuffer();

    Callable<ByteBuffer> lastEvent = () -> {
        clock.time = Instant.parse("2020-01-02T00:00:00Z");
        return event;
    };

    AsyncRequestBody requestBody = AsyncRequestBody.fromPublisher(Flowable.concatArray(Flowable.just(event),
                                                                                       Flowable.fromCallable(lastEvent)));

    AsyncRequestBody signedBody = SignerTestUtils.signAsyncRequest(signer, signedRequest, requestBody, credentials,
                                                                   signingName, clock, region.id());

    List<Message> signedMessages = readMessages(signedBody);
    assertThat(signedMessages.size()).isEqualTo(3);

    Map<String, HeaderValue> firstMessageHeaders = signedMessages.get(0).getHeaders();
    assertThat(firstMessageHeaders.get(":date").getTimestamp()).isEqualTo("2020-01-01T23:59:59Z");
    assertThat(Base64.getEncoder().encodeToString(firstMessageHeaders.get(":chunk-signature").getByteArray()))
        .isEqualTo("EFt7ZU043r/TJE8U+1GxJXscmNxoqmIdGtUIl8wE9u0=");

    Map<String, HeaderValue> lastMessageHeaders = signedMessages.get(2).getHeaders();
    assertThat(lastMessageHeaders.get(":date").getTimestamp()).isEqualTo("2020-01-02T00:00:00Z");
    assertThat(Base64.getEncoder().encodeToString(lastMessageHeaders.get(":chunk-signature").getByteArray()))
        .isEqualTo("UTRGo0D7BQytiVkH1VofR/8f3uFsM4V5QR1A8grr1+M=");

}
 
Example 18
Source File: SendMessageAttachment.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void send(byte[] attachment) throws AddressException, MessagingException, IOException {

        Session session = Session.getDefaultInstance(new Properties());

        // Create a new MimeMessage object
        MimeMessage message = new MimeMessage(session);

        // Add subject, from and to lines
        message.setSubject(SUBJECT, "UTF-8");
        message.setFrom(new InternetAddress(SENDER));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(RECIPIENT));

        // Create a multipart/alternative child container
        MimeMultipart msgBody = new MimeMultipart("alternative");

        // Create a wrapper for the HTML and text parts
        MimeBodyPart wrap = new MimeBodyPart();

        // Define the text part
        MimeBodyPart textPart = new MimeBodyPart();
        textPart.setContent(BODY_TEXT, "text/plain; charset=UTF-8");

        // Define the HTML part
        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setContent(BODY_HTML, "text/html; charset=UTF-8");

        // Add the text and HTML parts to the child container
        msgBody.addBodyPart(textPart);
        msgBody.addBodyPart(htmlPart);

        // Add the child container to the wrapper object
        wrap.setContent(msgBody);

        // Create a multipart/mixed parent container
        MimeMultipart msg = new MimeMultipart("mixed");

        // Add the parent container to the message
        message.setContent(msg);

        // Add the multipart/alternative part to the message
        msg.addBodyPart(wrap);

        // Define the attachment
        MimeBodyPart att = new MimeBodyPart();
        DataSource fds = new ByteArrayDataSource(attachment, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        att.setDataHandler(new DataHandler(fds));

        // Set the attachment name
        String reportName = "WorkReport.xls";
        att.setFileName(reportName);

        // Add the attachment to the message
        msg.addBodyPart(att);

        try {
            System.out.println("Attempting to send an email through Amazon SES " + "using the AWS SDK for Java...");

            Region region = Region.US_WEST_2;

            SesClient client = SesClient.builder().region(region).build();

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            message.writeTo(outputStream);

            ByteBuffer buf = ByteBuffer.wrap(outputStream.toByteArray());

            byte[] arr = new byte[buf.remaining()];
            buf.get(arr);

            SdkBytes data = SdkBytes.fromByteArray(arr);

            RawMessage rawMessage = RawMessage.builder()
                    .data(data)
                    .build();

            SendRawEmailRequest rawEmailRequest = SendRawEmailRequest.builder()
                    .rawMessage(rawMessage)
                    .build();

            client.sendRawEmail(rawEmailRequest);

        } catch (SdkException e) {
            e.getStackTrace();
        }
        // snippet-end:[ses.java2.sendmessageattachment.main]
    }
 
Example 19
Source File: PutItem.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {

        final String USAGE = "\n" +
                "Usage:\n" +
                "    PutItem <table> <key> <keyVal> <albumtitle> <albumtitleval> <awards> <awardsval> <Songtitle> <songtitleval>\n\n" +
                "Where:\n" +
                "    table - the table in which an item is placed (i.e., Music3),\n" +
                "    key -  the key used in the table (iei.e., Artist),\n" +
                "    keyval  - the key value that represents the item to get (i.e., Famous Band),\n" +
                "    albumTitle -  the album title (i.e., AlbumTitle),\n" +
                "    AlbumTitleValue -  the name of the album (i.e., Songs About Life ),\n" +
                "    Awards -  the awards column (i.e., Awards),\n" +
                "    AwardVal -  the value of the awards (i.e., 10),\n" +
                "    SongTitle -  the song title (i.e., SongTitle),\n" +
                "    SongTitleVal -  the value of the song title (i.e., Happy Day).\n" +
                "Example:\n" +
                "    Music3 Artist Famous Band AlbumTitle Songs About Life Awards 10 SongTitle Happy Day \n" +
                "**Warning** This program will actually place an item\n" +
                "            that you specify into a table!\n";

        if (args.length < 9) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String tableName = args[0];
        String key = args[1];
        String keyVal = args[2];
        String albumTitle = args[3];
        String albumTitleValue = args[4];
        String awards = args[5];
        String awardVal = args[6];
        String songTitle = args[7];
        String songTitleVal = args[8];

        // Create the DynamoDbClient object
        Region region = Region.US_WEST_2;
        DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
        System.out.println("Done!");

    }
 
Example 20
Source File: LambdaInvoke.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {


        if (args.length < 1) {
            System.out.println("Please specify a function name");
            System.exit(1);
        }

        // snippet-start:[lambda.java2.invoke.main]
        
        /*
        Function names appear as arn:aws:lambda:us-west-2:335556330391:function:HelloFunction
        you can retrieve the value by looking at the function in the AWS Console
        */
        String functionName = args[0];

        InvokeResponse res = null ;
        try {
            Region region = Region.US_WEST_2;
            LambdaClient awsLambda = LambdaClient.builder().region(region).build();

            //Need a SdkBytes instance for the payload
            SdkBytes payload = SdkBytes.fromUtf8String("{\n" +
                    " \"Hello \": \"Paris\",\n" +
                    " \"countryCode\": \"FR\"\n" +
                    "}" ) ;

            //Setup an InvokeRequest
            InvokeRequest request = InvokeRequest.builder()
                    .functionName(functionName)
                    .payload(payload)
                    .build();

            //Invoke the Lambda function
            res = awsLambda.invoke(request);

            //Get the response
            String value = res.payload().asUtf8String() ;

            //write out the response
            System.out.println(value);

        } catch(ServiceException e) {
            e.getStackTrace();
        }
        // snippet-end:[lambda.java2.invoke.main]
    }