List of usage examples for com.amazonaws.regions Region getRegion
public static Region getRegion(Regions region)
From source file:com.aegeus.aws.SimpleStorageService.java
License:Apache License
public SimpleStorageService(S3ConfigObject config) { this.config = config; s3 = new AmazonS3Client(new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey())); s3.setRegion(Region.getRegion(Regions.fromName(config.getRegion()))); }
From source file:com.amazon.AmazonClientManager.java
License:Apache License
public void validateCredentials() { if (sdbClient == null) { Log.i(LOG_TAG, "Creating New Clients."); Region region = Region.getRegion(Regions.AP_SOUTHEAST_1); AWSCredentials credentials = new BasicAWSCredentials(PropertyLoader.getInstance().getAccessKey(), PropertyLoader.getInstance().getSecretKey()); sdbClient = new AmazonSimpleDBClient(credentials); sdbClient.setRegion(region);/*from w w w. jav a 2 s . com*/ } }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java
License:Open Source License
@VisibleForTesting static AwsClientBuilder.EndpointConfiguration getEndpointConfiguration(final Optional<String> endpoint, final String signingRegion) { Preconditions.checkArgument(endpoint != null, "must provide an optional endpoint and not null"); Preconditions.checkArgument(!Strings.isNullOrEmpty(signingRegion), "must provide a signing region"); final String expectedServiceEndpoint = "https://" + Region.getRegion(Regions.fromName(signingRegion)) .getServiceEndpoint(AmazonDynamoDB.ENDPOINT_PREFIX); if (endpoint.isPresent() && !Strings.isNullOrEmpty(endpoint.get())) { final String regionParsedFromEndpoint = AwsHostNameUtils.parseRegion(endpoint.get(), AmazonDynamoDB.ENDPOINT_PREFIX); Preconditions.checkArgument(/*from w ww .jav a 2 s . c o m*/ regionParsedFromEndpoint == null || signingRegion.equals(regionParsedFromEndpoint)); return new AwsClientBuilder.EndpointConfiguration(endpoint.get(), signingRegion); } else { //Regions.fromName will throw IllegalArgumentException if signingRegion is not valid. return new AwsClientBuilder.EndpointConfiguration(expectedServiceEndpoint, signingRegion); } }
From source file:com.amazon.util.ImageUploader.java
public static void uploadImage(String imageURL, String imageName, String folderName, String bucketName) throws MalformedURLException, IOException { // credentials object identifying user for authentication AWSCredentials credentials = new BasicAWSCredentials(System.getenv("AWS_S3_ACCESS_KEY"), System.getenv("AWS_S3_SECRET_ACCESS_KEY")); // create a client connection based on credentials AmazonS3 s3client = new AmazonS3Client(credentials); try {//from ww w. j a va2 s . c om if (!(s3client.doesBucketExist(bucketName))) { s3client.setRegion(Region.getRegion(Regions.US_EAST_1)); // Note that CreateBucketRequest does not specify region. So bucket is // created in the region specified in the client. s3client.createBucket(new CreateBucketRequest(bucketName)); } //Enabe CORS: // <?xml version="1.0" encoding="UTF-8"?> //<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> // <CORSRule> // <AllowedOrigin>http://ask-ifr-download.s3.amazonaws.com</AllowedOrigin> // <AllowedMethod>GET</AllowedMethod> // </CORSRule> //</CORSConfiguration> BucketCrossOriginConfiguration configuration = new BucketCrossOriginConfiguration(); CORSRule corsRule = new CORSRule() .withAllowedMethods( Arrays.asList(new CORSRule.AllowedMethods[] { CORSRule.AllowedMethods.GET })) .withAllowedOrigins(Arrays.asList(new String[] { "http://ask-ifr-download.s3.amazonaws.com" })); configuration.setRules(Arrays.asList(new CORSRule[] { corsRule })); s3client.setBucketCrossOriginConfiguration(bucketName, configuration); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } String fileName = folderName + SUFFIX + imageName + ".png"; URL url = new URL(imageURL); ObjectMetadata omd = new ObjectMetadata(); omd.setContentType("image/png"); omd.setContentLength(url.openConnection().getContentLength()); // upload file to folder and set it to public s3client.putObject(new PutObjectRequest(bucketName, fileName, url.openStream(), omd) .withCannedAcl(CannedAccessControlList.PublicRead)); }
From source file:com.amediamanager.springconfig.ServerConfig.java
License:Apache License
@Bean @Scope(WebApplicationContext.SCOPE_APPLICATION) public Region region(final ConfigurationSettings settings) { return Region .getRegion(Regions.fromName(settings.getProperty(ConfigurationSettings.ConfigProps.AWS_REGION))); }
From source file:com.app.dynamoDb.DynamoFacebookUsers.java
License:Open Source License
public DynamoFacebookUsers() { // credentials = new ProfileCredentialsProvider("default").getCredentials(); dynamoDB = new AmazonDynamoDBClient(new AWSCredentialsProviderChain( new InstanceProfileCredentialsProvider(), new ClasspathPropertiesFileCredentialsProvider())); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2);// ww w . ja va 2 s. co m }
From source file:com.app.dynamoDb.DynamoUser.java
License:Open Source License
public DynamoUser() { //credentials = new ProfileCredentialsProvider("default").getCredentials(); dynamoDB = new AmazonDynamoDBClient(new AWSCredentialsProviderChain( new InstanceProfileCredentialsProvider(), new ClasspathPropertiesFileCredentialsProvider())); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2);/*from w w w . ja v a2 s. c o m*/ }
From source file:com.app.dynamoDb.DynamoUserAuthority.java
License:Open Source License
/** * The only information needed to create a client are security credentials * consisting of the AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints, are performed * automatically. Client parameters, such as proxies, can be specified in an * optional ClientConfiguration object when constructing a client. * * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration *//*from w w w . java 2s . co m*/ private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (C:\\Users\\yogeshrawat\\.aws\\credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("default").getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (C:\\Users\\yogeshrawat\\.aws\\credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2); }
From source file:com.app.ses.AmazonSES.java
License:Open Source License
public void sendMail(String TO, String USUARIO2, String SUBJECT, String CONTENIDO, String FOLIO, String USERCREATE, String NOMBRE) { // Construct an object to contain the recipient address. Destination destination = new Destination().withToAddresses(new String[] { TO }); // Create the subject and body of the message. Content subject = new Content().withData(SUBJECT); Content htmlContent = new Content().withData(" <body bgcolor=\"#FFFFFF\">\n" + " <!-- HEADER -->\n" + " <table class=\"head-wrap\" bgcolor=\"red\">\n" + " <tr>\n" + " <td></td>\n" + " <td class=\"header container\" >\n" + " <div class=\"content\">\n" + " <table bgcolor=\"red\">\n" + " <tr>\n" + " <td style=\"font-size: x-large; color:white;\">\n" + " S G C o n\n" + " </td>\n" + " <td style=\"text-align: right; color:white; fon\">\n" + " Notificaciones\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " </div>\n" + " </td>\n" + " <td></td>\n" + " </tr>\n" + " </table><!-- /HEADER -->\n" + " <!-- BODY -->\n" + " <table class=\"body-wrap\">\n" + " <tr>\n" + " <td></td>\n" + " <td class=\"container\" bgcolor=\"#FFFFFF\">\n" + " <div class=\"content\">\n" + " <table>\n" + " <tr>\n" + " <td>\n" + " <h3>Hola, " + USUARIO2 + "</h3>\n" + " <p class=\"callout\">\n" + " " + CONTENIDO + "\n" + " </p>\n" + " <p>\n" + " <table style=\"font-size: medium\">\n" + " <tr>\n" + " <td>Folio: " + FOLIO + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td>" + USERCREATE + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td>" + NOMBRE + "</td>\n" + " </tr>\n" + " </table>\n" + " </p> <br/>\n" + " <table>\n" + " <tr>\n" + " <td>\n" + " <p>\n" + " <a href=\"http://www.sgcon-infonavit.com\" class=\"soc-btn fb\">Ir a la aplicacin</a> \n" + " </p>\n" + " </td>\n" + " </tr>\n" + " </table\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " </div>\n" + " </td>\n" + " <td></td>\n" + " </tr>\n" + " </table>\n" + " </body>"); Body body = new Body().withHtml(htmlContent); // Create a message with the specified subject and body. Message message = new Message().withSubject(subject).withBody(body); // Assemble the email. SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination) .withMessage(message);/*from w w w. j a va 2s .co m*/ try { System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java..."); /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). * * TransferManager manages a pool of threads, so we create a * single instance and share it throughout our application. */ /*AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException( "Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); }*/ AWSCredentials awsCreds = new BasicAWSCredentials("AKIAJFO4NNHIPNTB4ZCQ", "VjYeQ9+xj3HAcLBSxxxbHTo6jy2ft0wF6tgWZXmA"); // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials. //AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials); AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(awsCreds); // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production // access status, sending limits, and Amazon SES identity-related settings are specific to a given // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are US_WEST_2 // and EU_WEST_1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Region REGION = Region.getRegion(Regions.US_WEST_2); client.setRegion(REGION); // Send the email. client.sendEmail(request); System.out.println("Email sent!"); } catch (Exception ex) { System.out.println("The email was not sent."); System.out.println("Error message: " + ex.getMessage()); } }
From source file:com.app.ses.AmazonSES.java
License:Open Source License
public void sendMailDos(String TO, String USUARIO2, String SUBJECT, String CONTENIDO, String LISTA) { System.out.println("Si imprime la llamada del la clase djscnlskdncfksdlncfksdcldsncewldn"); //operaciones con el json // Construct an object to contain the recipient address. Destination destination = new Destination().withToAddresses(new String[] { TO }); // Create the subject and body of the message. Content subject = new Content().withData(SUBJECT); Content htmlContent = new Content().withData(" <body bgcolor=\"#FFFFFF\">\n" + " <!-- HEADER -->\n" + " <table class=\"head-wrap\" bgcolor=\"red\">\n" + " <tr>\n" + " <td></td>\n" + " <td class=\"header container\" >\n" + " <div class=\"content\">\n" + " <table bgcolor=\"red\">\n" + " <tr>\n" + " <td style=\"font-size: x-large; color:white;\">\n" + " S G C o n\n" + " </td>\n" + " <td style=\"text-align: right; color:white; fon\">\n" + " Notificaciones\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " </div>\n" + " </td>\n" + " <td></td>\n" + " </tr>\n" + " </table><!-- /HEADER -->\n" + " <!-- BODY -->\n" + " <table class=\"body-wrap\">\n" + " <tr>\n" + " <td></td>\n" + " <td class=\"container\" bgcolor=\"#FFFFFF\">\n" + " <div class=\"content\">\n" + " <table>\n" + " <tr>\n" + " <td>\n" + " <h3>Hola, " + USUARIO2 + "</h3>\n" + " <p class=\"callout\">\n" + " " + CONTENIDO + "\n" + " </p>\n" + " <p>\n" + " <table style=\"font-size: medium\">\n" + " <tr>\n" + " <td>Folio: " + LISTA + "</td>\n" + " </tr>\n" + " </table>\n" + " </p> <br/>\n" + " <table>\n" + " <tr>\n" + " <td>\n" + " <p>\n" + " <a href=\"http://www.sgcon-infonavit.com\" class=\"soc-btn fb\">Ir a la aplicacin</a> \n" + " </p>\n" + " </td>\n" + " </tr>\n" + " </table\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " </div>\n" + " </td>\n" + " <td></td>\n" + " </tr>\n" + " </table>\n" + " </body>"); Body body = new Body().withHtml(htmlContent); // Create a message with the specified subject and body. Message message = new Message().withSubject(subject).withBody(body); // Assemble the email. SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination) .withMessage(message);//ww w . ja v a 2s . c o m try { System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java..."); /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). * * TransferManager manages a pool of threads, so we create a * single instance and share it throughout our application. */ /*AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException( "Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); }*/ AWSCredentials awsCreds = new BasicAWSCredentials("AKIAJFO4NNHIPNTB4ZCQ", "VjYeQ9+xj3HAcLBSxxxbHTo6jy2ft0wF6tgWZXmA"); // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials. //AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials); AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(awsCreds); // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production // access status, sending limits, and Amazon SES identity-related settings are specific to a given // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are US_WEST_2 // and EU_WEST_1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Region REGION = Region.getRegion(Regions.US_WEST_2); client.setRegion(REGION); // Send the email. client.sendEmail(request); System.out.println("Email sent!"); } catch (Exception ex) { System.out.println("The email was not sent."); System.out.println("Error message: " + ex.getMessage()); } }