Skip to content

Commit

Permalink
Merge branch 'master' into dougsch-go-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug-AWS committed Jan 23, 2020
2 parents 36c9607 + 1c48f50 commit 9007085
Show file tree
Hide file tree
Showing 22 changed files with 936 additions and 167 deletions.
12 changes: 7 additions & 5 deletions dotnet/example_code/S3/S3ShowTextItem.cs
Expand Up @@ -6,8 +6,8 @@
//snippet-keyword:[Amazon S3]
//snippet-service:[s3]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2019-11-18]
//snippet-sourceauthor:[Doug-AWS]
//snippet-sourcedate:[2020-01-18]
//snippet-sourceauthor:[AWS-NET-DG]
/*******************************************************************************
* Copyright 2009-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
Expand Down Expand Up @@ -75,9 +75,11 @@ public static void Main(string[] args)

string responseBody = reader.ReadToEnd();

FileStream s = new FileStream(args[3], FileMode.Create);
StreamWriter writer = new StreamWriter(s);
writer.WriteLine(responseBody);
using(FileStream s = new FileStream(args[3], FileMode.Create))
using(StreamWriter writer = new StreamWriter(s))
{
writer.WriteLine(responseBody);
}
}
catch (AmazonS3Exception s3Exception)
{
Expand Down
8 changes: 4 additions & 4 deletions go/example_code/cloudtrail/create_trail.go
@@ -1,11 +1,11 @@
// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]
// snippet-sourceauthor:[Doug-AWS]
// snippet-sourcedescription:[Describes the Amazon Cloudwatch alarms.]
// snippet-keyword:[Amazon CloudWatch]
// snippet-keyword:[DescribeAlarms function]
// snippet-sourcedescription:[create_trail.go demonstrates how to create a CloudTrail trail.]
// snippet-keyword:[Amazon CloudTrail]
// snippet-keyword:[CreateTrail function]
// snippet-keyword:[Go]
// snippet-sourcesyntax:[go]
// snippet-service:[cloudwatch]
// snippet-service:[cloudtrail]
// snippet-keyword:[Code Sample]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[2020-1-6]
Expand Down
@@ -1,15 +1,5 @@
// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]
// snippet-sourcedescription:[UseDynamoMapping.java demonstrates how to use the DynamoDB mapping functionality]
// snippet-service:[dynamodb]
// snippet-keyword:[Java]
// snippet-keyword:[Amazon DynamoDB]
// snippet-keyword:[Code Sample]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[2019-12-16]
// snippet-sourceauthor:[scmacdon-AWS]

/*
Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
This file is licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License. A copy of
the License is located at
Expand All @@ -19,6 +9,16 @@
specific language governing permissions and limitations under the License.
*/

// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]
// snippet-sourcedescription:[UseDynamoMapping.java demonstrates how to use the DynamoDB mapping functionality]
// snippet-service:[dynamodb]
// snippet-keyword:[Java]
// snippet-keyword:[Amazon DynamoDB]
// snippet-keyword:[Code Sample]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[2019-12-16]
// snippet-sourceauthor:[scmacdon-AWS]

// snippet-start:[dynamodb.java.dynamoDB_mapping.complete]
package aws.example.dynamodb;

Expand All @@ -35,8 +35,8 @@

public class UseDynamoMapping {

public static void main(String[] args)
{
public static void main(String[] args) {

final String USAGE = "\n" +
"To run this example, supply the following values: \n" +
"artist name \n" +
Expand All @@ -56,42 +56,40 @@ public static void main(String[] args)


// snippet-start:[dynamodb.java.dynamoDB_mapping.main]
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
MusicItems items = new MusicItems();
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
MusicItems items = new MusicItems();

try{
// Add new content to the Music table
items.setArtist(artist);
items.setSongTitle(songTitle);
items.setAlbumTitle(albumTitle);
items.setAwards(Integer.parseInt(awards)); //convert to an int
try{
// Add new content to the Music table
items.setArtist(artist);
items.setSongTitle(songTitle);
items.setAlbumTitle(albumTitle);
items.setAwards(Integer.parseInt(awards)); //convert to an int

// Save the item
DynamoDBMapper mapper = new DynamoDBMapper(client);
mapper.save(items);
// Save the item
DynamoDBMapper mapper = new DynamoDBMapper(client);
mapper.save(items);

// Load an item based on the Partition Key and Sort Key
// Both values need to be passed to the mapper.load method
String artistName = artist;
String songQueryTitle = songTitle;
// Both values need to be passed to the mapper.load method
String artistName = artist;
String songQueryTitle = songTitle;

// Retrieve the item
MusicItems itemRetrieved = mapper.load(MusicItems.class, artistName, songQueryTitle);
System.out.println("Item retrieved:");
System.out.println(itemRetrieved);
// Retrieve the item
MusicItems itemRetrieved = mapper.load(MusicItems.class, artistName, songQueryTitle);
System.out.println("Item retrieved:");
System.out.println(itemRetrieved);

// Modify the Award value
itemRetrieved.setAwards(2);
mapper.save(itemRetrieved);
System.out.println("Item updated:");
System.out.println(itemRetrieved);

System.out.print("Done");
}
catch (AmazonDynamoDBException e)
{
e.getStackTrace();
}
itemRetrieved.setAwards(2);
mapper.save(itemRetrieved);
System.out.println("Item updated:");
System.out.println(itemRetrieved);

System.out.print("Done");
} catch (AmazonDynamoDBException e) {
e.getStackTrace();
}
}

@DynamoDBTable(tableName="Music")
Expand All @@ -104,20 +102,40 @@ public static class MusicItems {
private int awards;

@DynamoDBHashKey(attributeName="Artist")
public String getArtist() { return this.artist; }
public void setArtist(String artist) {this.artist = artist; }
public String getArtist() {
return this.artist;
}

public void setArtist(String artist) {
this.artist = artist;
}

@DynamoDBRangeKey(attributeName="SongTitle")
public String getSongTitle() { return this.songTitle; }
public void setSongTitle(String title) {this.songTitle = title; }
public String getSongTitle() {
return this.songTitle;
}

public void setSongTitle(String title) {
this.songTitle = title;
}

@DynamoDBAttribute(attributeName="AlbumTitle")
public String getAlbumTitle() { return this.albumTitle; }
public void setAlbumTitle(String title) {this.albumTitle = title; }
public String getAlbumTitle() {
return this.albumTitle;
}

public void setAlbumTitle(String title) {
this.albumTitle = title;
}

@DynamoDBAttribute(attributeName="Awards")
public int getAwards() { return this.awards; }
public void setAwards(int awards) {this.awards = awards; }
public int getAwards() {
return this.awards;
}

public void setAwards(int awards) {
this.awards = awards;
}
}
// snippet-end:[dynamodb.java.dynamoDB_mapping.main]
}
Expand Down
Expand Up @@ -28,11 +28,16 @@
// snippet-start:[ec2.java1.running_instances.import]
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder;
import com.amazonaws.services.ec2.model.*;
import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
import com.amazonaws.services.ec2.model.DescribeInstancesResult;
import com.amazonaws.services.ec2.model.Filter;
import com.amazonaws.services.ec2.model.Reservation;
import com.amazonaws.services.ec2.model.Instance;
import com.amazonaws.SdkClientException;

// snippet-end:[ec2.java1.running_instances.import]

public class FindRunningInstances{
public class FindRunningInstances {

public static void main(String[] args) {

Expand All @@ -55,7 +60,7 @@ public static void main(String[] args) {

for (Instance instance : reservation.getInstances()) {

//Print out the results
//Print out the results
System.out.printf(
"Found reservation with id %s, " +
"AMI %s, " +
Expand All @@ -67,12 +72,11 @@ public static void main(String[] args) {
instance.getInstanceType(),
instance.getState().getName(),
instance.getMonitoring().getState());
}
}
}
System.out.print("Done");
}
catch (Exception e)
{
System.out.print("Done");

} catch (SdkClientException e) {
e.getStackTrace();
}
// snippet-end:[ec2.java1.running_instances.main]
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This file is licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License. A copy of
Expand Down Expand Up @@ -35,7 +35,6 @@
import com.amazonaws.services.lambda.model.DeleteFunctionRequest;
// snippet-end:[lambda.java1.delete.import]


public class DeleteFunction {

public static void main(String[] args) {
Expand All @@ -48,21 +47,21 @@ public static void main(String[] args) {
// snippet-start:[lambda.java1.delete.main]
String functionName = args[0];
try {
AWSLambda awsLambda = AWSLambdaClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider())
.withRegion(Regions.US_WEST_2).build();
AWSLambda awsLambda = AWSLambdaClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider())
.withRegion(Regions.US_WEST_2).build();

DeleteFunctionRequest delFunc = new DeleteFunctionRequest();
delFunc.withFunctionName(functionName);
DeleteFunctionRequest delFunc = new DeleteFunctionRequest();
delFunc.withFunctionName(functionName);

//Delete the functiom
awsLambda.deleteFunction(delFunc);
System.out.println("The function is deleted");
}
catch (ServiceException e) {
System.out.println(e);
}
//Delete the functiom
awsLambda.deleteFunction(delFunc);
System.out.println("The function is deleted");

} catch (ServiceException e) {
System.out.println(e);
}
// snippet-end:[lambda.java1.delete.main]
}
}
}
// snippet-end:[lambda.java1.DeleteFunction.complete]
@@ -1,5 +1,5 @@
/**
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This file is licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License. A copy of
Expand Down Expand Up @@ -33,6 +33,8 @@
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
import com.amazonaws.services.lambda.model.InvokeRequest;
import com.amazonaws.services.lambda.model.InvokeResult;
import com.amazonaws.services.lambda.model.ServiceException;

import java.nio.charset.StandardCharsets;
// snippet-end:[lambda.java1.invoke.import]

Expand Down Expand Up @@ -72,8 +74,8 @@ public static void main(String[] args) {

//write out the return value
System.out.println(ans);
}
catch (Exception e) {

} catch (ServiceException e) {
System.out.println(e);
}

Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This file is licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License. A copy of
Expand Down Expand Up @@ -60,8 +60,8 @@ public static void main(String[] args) {

System.out.println("The function name is "+config.getFunctionName());
}
}
catch (ServiceException e) {

} catch (ServiceException e) {
System.out.println(e);
}
// snippet-end:[lambda.java1.list.main]
Expand Down

0 comments on commit 9007085

Please sign in to comment.