List of usage examples for com.amazonaws.regions Regions DEFAULT_REGION
Regions DEFAULT_REGION
To view the source code for com.amazonaws.regions Regions DEFAULT_REGION.
Click Source Link
From source file:com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl.java
License:Open Source License
public AWSCredentials getCredentials() { AWSCredentials initialCredentials = new BasicAWSCredentials(accessKey, secretKey.getPlainText()); if (StringUtils.isBlank(iamRoleArn)) { return initialCredentials; } else {/*from ww w. java 2 s . co m*/ // Check for available region from the SDK, otherwise specify default String clientRegion = null; DefaultAwsRegionProviderChain sdkRegionLookup = new DefaultAwsRegionProviderChain(); try { clientRegion = sdkRegionLookup.getRegion(); } catch (com.amazonaws.SdkClientException e) { LOGGER.log(Level.WARNING, "Could not find default region using SDK lookup.", e); } if (clientRegion == null) { clientRegion = Regions.DEFAULT_REGION.getName(); } AWSSecurityTokenService client; // Handle the case of delegation to instance profile if (StringUtils.isBlank(accessKey) && StringUtils.isBlank(secretKey.getPlainText())) { client = AWSSecurityTokenServiceClientBuilder.standard().withRegion(clientRegion).build(); } else { client = AWSSecurityTokenServiceClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(initialCredentials)) .withRegion(clientRegion).build(); } AssumeRoleRequest assumeRequest = createAssumeRoleRequest(iamRoleArn) .withDurationSeconds(this.getStsTokenDuration()); AssumeRoleResult assumeResult = client.assumeRole(assumeRequest); return new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken()); } }
From source file:com.facebook.presto.dynamodb.DynamodbConfig.java
License:Apache License
public Region getAWSRegion() { return Region.getRegion(region == null ? Regions.DEFAULT_REGION : Regions.fromName(region)); }
From source file:com.kixeye.chassis.support.metrics.aws.DefaultCloudWatchFactory.java
License:Apache License
private Region getCloudWatchRegion(String region) { if ("default".equals(region)) { return Region.getRegion(Regions.DEFAULT_REGION); }//from www. j a v a 2 s .c o m return Region.getRegion(Regions.fromName(region)); }
From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.IamRoleCachingAgent.java
License:Apache License
@Override public CacheResult loadData(ProviderCache providerCache) { AmazonIdentityManagement iam = amazonClientProvider.getIam(accountName, awsCredentialsProvider, Regions.DEFAULT_REGION.getName()); Set<IamRole> cacheableRoles = fetchIamRoles(iam, accountName); Map<String, Collection<CacheData>> newDataMap = generateFreshData(cacheableRoles); Collection<CacheData> newData = newDataMap.get(IAM_ROLE.toString()); Set<String> oldKeys = providerCache.getAll(IAM_ROLE.toString()).stream().map(CacheData::getId) .filter(this::keyAccountFilter).collect(Collectors.toSet()); Map<String, Collection<String>> evictionsByKey = computeEvictableData(newData, oldKeys); logUpcomingActions(newDataMap, evictionsByKey); return new DefaultCacheResult(newDataMap, evictionsByKey); }
From source file:com.netflix.spinnaker.clouddriver.lambda.provider.agent.IamRoleCachingAgent.java
License:Apache License
@Override public CacheResult loadData(ProviderCache providerCache) { AmazonIdentityManagement iam = amazonClientProvider.getIam(account, Regions.DEFAULT_REGION.getName(), false);//from w w w . j a va 2 s . c o m Set<IamRole> cacheableRoles = fetchIamRoles(iam, accountName); Map<String, Collection<CacheData>> newDataMap = generateFreshData(cacheableRoles); Collection<CacheData> newData = newDataMap.get(IAM_ROLE.toString()); Set<String> oldKeys = providerCache.getAll(IAM_ROLE.toString()).stream().map(CacheData::getId) .filter(this::keyAccountFilter).collect(Collectors.toSet()); Map<String, Collection<String>> evictionsByKey = computeEvictableData(newData, oldKeys); logUpcomingActions(newDataMap, evictionsByKey); return new DefaultCacheResult(newDataMap, evictionsByKey); }
From source file:com.openlattice.aws.AwsS3Pod.java
License:Open Source License
public static AmazonS3 newS3Client(AmazonLaunchConfiguration awsConfig) { AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard(); builder.setRegion(Region.getRegion(awsConfig.getRegion().or(Regions.DEFAULT_REGION)).getName()); return builder.build(); }
From source file:com.twitter.heron.uploader.s3.S3Context.java
License:Open Source License
public static String region(Config config) { return config.getStringValue(HERON_UPLOADER_S3_REGION, Regions.DEFAULT_REGION.getName()); }
From source file:de.taimos.pipeline.aws.AWSClientFactory.java
License:Apache License
private static Region getRegion(EnvVars vars) { if (vars.get(AWS_DEFAULT_REGION) != null) { return Region.getRegion(Regions.fromName(vars.get(AWS_DEFAULT_REGION))); }//from w w w.j a va2 s . c o m if (vars.get(AWS_REGION) != null) { return Region.getRegion(Regions.fromName(vars.get(AWS_REGION))); } if (System.getenv(AWS_DEFAULT_REGION) != null) { return Region.getRegion(Regions.fromName(System.getenv(AWS_DEFAULT_REGION))); } if (System.getenv(AWS_REGION) != null) { return Region.getRegion(Regions.fromName(System.getenv(AWS_REGION))); } Region currentRegion = Regions.getCurrentRegion(); if (currentRegion != null) { return currentRegion; } return Region.getRegion(Regions.DEFAULT_REGION); }
From source file:org.datacleaner.windows.DynamoDbDatastoreDialog.java
License:Open Source License
@Inject public DynamoDbDatastoreDialog(final WindowContext windowContext, final MutableDatastoreCatalog catalog, @Nullable final DynamoDbDatastore originalDatastore, final UserPreferences userPreferences) { super(originalDatastore, catalog, windowContext, userPreferences); _regionField = new DCComboBox<>(Regions.values()); _regionField.setSelectedItem(Regions.DEFAULT_REGION); _accessKeyIdField = WidgetFactory.createTextField(); _secretAccessKeyField = WidgetFactory.createPasswordField(); _accessKeyIdField.getDocument().addDocumentListener(new DCDocumentListener() { @Override/*w w w .j av a 2 s . co m*/ protected void onChange(final DocumentEvent event) { validateAndUpdate(); } }); _secretAccessKeyField.getDocument().addDocumentListener(new DCDocumentListener() { @Override protected void onChange(final DocumentEvent event) { validateAndUpdate(); } }); if (originalDatastore == null) { _tableDefinitionWidget = new TableDefinitionOptionSelectionPanel(windowContext, this, null); } else { _datastoreNameTextField.setText(originalDatastore.getName()); _datastoreNameTextField.setEnabled(false); _accessKeyIdField.setText(originalDatastore.getAccessKeyId()); _secretAccessKeyField.setText(originalDatastore.getSecretAccessKey()); final String originalRegion = originalDatastore.getRegion(); try { final Regions region = Regions.fromName(originalRegion); _regionField.setSelectedItem(region); } catch (IllegalArgumentException e) { // unable to resolve region, ignore. } _tableDefinitionWidget = new TableDefinitionOptionSelectionPanel(windowContext, this, originalDatastore.getTableDefs()); } }
From source file:org.juneja.eventdemo.utils.AmazonSimpleQueueService.java
License:Open Source License
public static void main(String[] args) throws Exception { /*/* ww w. j a va 2 s .co m*/ * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ 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); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.DEFAULT_REGION); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { // Create a queue // System.out.println("Creating a new SQS queue called MyQueue.\n"); // CreateQueueRequest createQueueRequest = new CreateQueueRequest("TestQueue_EventDriven_2"); // String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); GetQueueUrlResult queueResult = sqs.getQueueUrl("TestQueue_EventDriven_2"); String myQueueUrl = queueResult.getQueueUrl(); // List queues System.out.println("Listing all queues in your account.\n"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } System.out.println(); // Send a message //System.out.println("Sending a message to MyQueue.\n"); //sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my new text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); System.out.println("Number of messages : " + messages.size()); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); // Delete a message //System.out.println("Deleting a message.\n"); //String messageRecieptHandle = messages.get(0).getReceiptHandle(); //sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); // Delete a queue /** System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); **/ } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, 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 " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }