List of usage examples for com.amazonaws.regions Region getRegion
public static Region getRegion(Regions region)
From source file:com.nike.cerberus.module.CerberusModule.java
License:Apache License
/** * Binds all the Amazon services used./*from w w w . ja v a 2 s . c o m*/ */ @Override protected void configure() { final Region region = Region.getRegion(Regions.fromName(regionName)); bind(AmazonEC2.class).toInstance(createAmazonClientInstance(AmazonEC2Client.class, region)); bind(AmazonCloudFormation.class) .toInstance(createAmazonClientInstance(AmazonCloudFormationClient.class, region)); bind(AmazonIdentityManagement.class) .toInstance(createAmazonClientInstance(AmazonIdentityManagementClient.class, region)); bind(AWSKMS.class).toInstance(createAmazonClientInstance(AWSKMSClient.class, region)); bind(AmazonS3.class).toInstance(createAmazonClientInstance(AmazonS3Client.class, region)); bind(AmazonAutoScaling.class).toInstance(createAmazonClientInstance(AmazonAutoScalingClient.class, region)); bind(AWSSecurityTokenService.class) .toInstance(createAmazonClientInstance(AWSSecurityTokenServiceClient.class, region)); bind(AWSLambda.class).toInstance(createAmazonClientInstance(AWSLambdaClient.class, region)); }
From source file:com.nike.cerberus.operation.gateway.CreateCloudFrontSecurityGroupUpdaterLambdaOperation.java
License:Apache License
@Inject public CreateCloudFrontSecurityGroupUpdaterLambdaOperation(final CloudFormationService cloudFormationService, final EnvironmentMetadata environmentMetadata, @Named(CF_OBJECT_MAPPER) final ObjectMapper cloudformationObjectMapper, AWSLambda awsLambda, AmazonS3 amazonS3) {//from w w w . j ava 2s . c o m this.cloudFormationService = cloudFormationService; this.cloudformationObjectMapper = cloudformationObjectMapper; this.environmentMetadata = environmentMetadata; this.awsLambda = awsLambda; this.amazonS3 = amazonS3; final Region region = Region.getRegion(Regions.US_EAST_1); AmazonCloudFormation amazonCloudFormation = new AmazonCloudFormationClient(); amazonCloudFormation.setRegion(region); amazonSNS = new AmazonSNSClient(); amazonSNS.setRegion(region); }
From source file:com.nike.cerberus.service.AuthenticationService.java
License:Apache License
/** * Encrypts the data provided using KMS based on the provided region and key id. * * @param regionName Region where key is located * @param keyId Key id/*from w ww . j av a2 s . c om*/ * @param data Data to be encrypted * @return encrypted data */ private byte[] encrypt(final String regionName, final String keyId, final byte[] data) { Region region; try { region = Region.getRegion(Regions.fromName(regionName)); } catch (IllegalArgumentException iae) { throw ApiException.newBuilder().withApiErrors(DefaultApiError.AUTH_IAM_ROLE_AWS_REGION_INVALID) .withExceptionCause(iae).build(); } final AWSKMSClient kmsClient = kmsClientFactory.getClient(region); try { final EncryptResult encryptResult = kmsClient .encrypt(new EncryptRequest().withKeyId(keyId).withPlaintext(ByteBuffer.wrap(data))); return encryptResult.getCiphertextBlob().array(); } catch (AmazonClientException ace) { throw ApiException.newBuilder().withApiErrors(DefaultApiError.INTERNAL_SERVER_ERROR) .withExceptionCause(ace) .withExceptionMessage( String.format("Unexpected error communicating with AWS KMS for region %s.", regionName)) .build(); } }
From source file:com.nike.cerberus.store.ConfigStore.java
License:Apache License
private void initEncryptedConfigStoreService() { if (encryptedConfigStoreService == null) { final Environment environment = getEnvironmentData(); KMSEncryptionMaterialsProvider materialProvider = new KMSEncryptionMaterialsProvider( environment.getConfigKeyId()); AmazonS3EncryptionClient encryptionClient = new AmazonS3EncryptionClient( new DefaultAWSCredentialsProviderChain(), materialProvider, new CryptoConfiguration().withAwsKmsRegion(Region.getRegion(environmentMetadata.getRegions()))) .withRegion(Region.getRegion(environmentMetadata.getRegions())); encryptedConfigStoreService = new S3StoreService(encryptionClient, environmentMetadata.getBucketName(), ""); }//from ww w .j a v a 2s . c om }
From source file:com.ninetoseven.inmuebles.AmazonClientManager.java
License:Open Source License
private void initClients() { AWSCredentials credentials = AmazonSharedPreferencesWrapper .getCredentialsFromSharedPreferences(this.sharedPreferences); Region region = Region.getRegion(Regions.US_EAST_1); s3Client = new AmazonS3Client(credentials); s3Client.setRegion(region);/*from w w w .ja va 2 s . c om*/ sqsClient = new AmazonSQSClient(credentials); sqsClient.setRegion(region); sdbClient = new AmazonSimpleDBClient(credentials); sdbClient.setRegion(region); snsClient = new AmazonSNSClient(credentials); snsClient.setRegion(region); }
From source file:com.numenta.taurus.service.TaurusClient.java
License:Open Source License
/** * Construct Taurus API client./* w ww .j a v a 2 s. co m*/ * * @param provider The AWS credential provider to use. * Usually {@link TaurusApplication#getAWSCredentialProvider()} * @param serverUrl DynamoDB Server. Use "http://10.0.2.2:8300" for local server or * null for AWS */ public TaurusClient(AWSCredentialsProvider provider, String serverUrl) { _server = serverUrl; AWSCredentialsProvider credentialsProvider = provider; if (credentialsProvider == null) { // Use Dummy credentials for local server credentialsProvider = new StaticCredentialsProvider(new AWSCredentials() { public String getAWSAccessKeyId() { // Returns dummy value return "taurus"; } @Override public String getAWSSecretKey() { // Returns dummy value return "taurus"; } }); } _awsClient = new AmazonDynamoDBClient(credentialsProvider); if (BuildConfig.REGION != null) { // Override default region _awsClient.setRegion(Region.getRegion(Regions.fromName(BuildConfig.REGION))); } if (_server != null) { // Override server endpoint, Usually the local DynamoDB server _awsClient.setEndpoint(_server); } }
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.optimalbi.GUI.java
License:Apache License
private void loadSettings() { if (!settingsFile.exists()) { try {/* w ww. j a v a 2 s . c om*/ if (!settingsFile.createNewFile()) { logger.error("Failed to create settings file"); return; } } catch (IOException e) { logger.error("Failed to create settings file " + e.getMessage()); } allRegions = new ArrayList<>(); currentRegions = new ArrayList<>(); Regions[] regionses = Regions.values(); for (Regions re : regionses) { if (!Region.getRegion(re).getName().equals(Regions.GovCloud.getName()) & !Region.getRegion(re).getName().equals(Regions.CN_NORTH_1.getName())) { AmazonRegion tempRegion; if (re.getName().equals(Regions.AP_SOUTHEAST_2.getName())) { tempRegion = new AmazonRegion(Region.getRegion(re), true); currentRegions.add(Region.getRegion(re)); } else { tempRegion = new AmazonRegion(Region.getRegion(re), false); } allRegions.add(tempRegion); } } saveSettings(); } BufferedReader fileReader = null; allRegions = new ArrayList<>(); currentRegions = new ArrayList<>(); List<String> activeRegions = new ArrayList<>(); try { fileReader = new BufferedReader(new FileReader(settingsFile)); String line = fileReader.readLine(); while (line != null) { String[] split = line.split(" "); if (split.length > 1) { switch (split[0].toLowerCase()) { case "regions": String[] argument = split[1].split(","); if (argument.length > 0) { Collections.addAll(activeRegions, argument); } break; case "password": encryptedPassword = split[1]; break; default: logger.warn("Unknown setting " + split[0]); break; } } else { if (!split[0].equals("")) logger.warn("No data entered for " + split[0]); } line = fileReader.readLine(); } } catch (IOException e) { logger.error("Failed to read settings file: " + e.getMessage()); setLabelCentre("Failed to read settings file: " + e.getMessage()); } Regions[] regionses = Regions.values(); for (Regions re : regionses) { if (!Region.getRegion(re).getName().equals(Regions.GovCloud.getName()) & !Region.getRegion(re).getName().equals(Regions.CN_NORTH_1.getName())) { AmazonRegion tempRegion; if (activeRegions.contains(re.getName())) { tempRegion = new AmazonRegion(Region.getRegion(re), true); currentRegions.add(Region.getRegion(re)); } else { tempRegion = new AmazonRegion(Region.getRegion(re), false); } allRegions.add(tempRegion); } } }
From source file:com.osecurityapp.PubSubActivity.java
License:Open Source License
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Obtain a reference to the mobile client. It is created in the Application class, // but in case a custom Application class is not used, we initialize it here if necessary. AWSMobileClient.initializeMobileClientIfNecessary(this); // Obtain a reference to the mobile client. It is created in the Application class. final AWSMobileClient awsMobileClient = AWSMobileClient.defaultMobileClient(); // Obtain a reference to the identity manager. //identityManager = awsMobileClient.getIdentityManager(); setupToolbar(savedInstanceState);//from ww w . j av a 2 s. co m setupNavigationMenu(savedInstanceState); //LayoutInflater inflater = this.getLayoutInflater(); //ViewGroup viewGroup = (ViewGroup) findViewById(android.R.id.content); //View homeView = inflater.inflate(R.layout.fragment_home , viewGroup); //snapshotView = (ImageView) homeView.findViewById(R.id.snapshotView); //snapshotView.setImageResource(android.R.drawable.alert_dark_frame); /** * Firebase subscription logic, started on runtime * */ FirebaseMessaging.getInstance().subscribeToTopic("varsler"); String msg = "Subscribed to topic varsler"; Log.d(LOG_TAG, msg); //firebaseToken = FirebaseInstanceId.getInstance().getToken(); //Log.d(LOG_TAG, firebaseToken); if (!AWSMobileClient.defaultMobileClient().getIdentityManager().isUserSignedIn()) { // In the case that the activity is restarted by the OS after the application // is killed we must redirect to the splash activity to handle the sign-in flow. Intent intent = new Intent(this, SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return; } setupSignInButtons(); // register settings changed receiver. LocalBroadcastManager.getInstance(this).registerReceiver(settingsChangedReceiver, new IntentFilter(UserSettings.ACTION_SETTINGS_CHANGED)); updateColor(); syncUserSettings(); /** * txtSubcribe = (EditText) findViewById(R.id.txtSubcribe); txtTopic = (EditText) findViewById(R.id.txtTopic); txtMessage = (EditText) findViewById(R.id.txtMessage); tvLastMessage = (TextView) findViewById(R.id.tvLastMessage); tvClientId = (TextView) findViewById(R.id.tvClientId); tvStatus = (TextView) findViewById(R.id.tvStatus); btnConnect = (Button) findViewById(R.id.btnConnect); btnConnect.setOnClickListener(handleS3); btnConnect.setEnabled(false); btnSubscribe = (Button) findViewById(R.id.btnSubscribe); btnSubscribe.setOnClickListener(subscribeClick); btnPublish = (Button) findViewById(R.id.btnPublish); btnPublish.setOnClickListener(publishClick); btnDisconnect = (Button) findViewById(R.id.btnDisconnect); btnDisconnect.setOnClickListener(disconnectClick); */ // MQTT client IDs are required to be unique per AWS IoT account. // This UUID is "practically unique" but does not _guarantee_ // uniqueness. // tvClientId.setText(clientId); //TODO Fix NotAuthorizedException by using "setLogins" earlier AuthenticationResultType authenticationResultType = new AuthenticationResultType(); String idToken = authenticationResultType.getIdToken(); //String idToken = cognitoUserSession.getIdToken().getJWTToken(); // Initialize the AWS Cognito credentials provider credentialsProvider = new CognitoCachingCredentialsProvider(getApplicationContext(), COGNITO_POOL_ID, MY_REGION); Map<String, String> logins = new HashMap<String, String>(); logins.put("eu-west-1_2F3hyifQN", idToken); credentialsProvider.setLogins(logins); Region region = Region.getRegion(MY_REGION); //s3 = new AmazonS3Client(credentialsProvider); // The following block uses IAM user credentials for authentication with AWS IoT. //awsCredentials = new BasicAWSCredentials("ACCESS_KEY_CHANGE_ME", "SECRET_KEY_CHANGE_ME"); //btnConnect.setEnabled(true); // The following block uses a Cognito credentials provider for authentication with AWS IoT. new Thread(new Runnable() { @Override public void run() { //@awsCredentials = credentialsProvider.getCredentials(); runOnUiThread(new Runnable() { @Override public void run() { } }); } }).start(); //handleS3(); }
From source file:com.pa3.cloudkon.remote.Dynamodb.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. * *///from w w w . j a va 2 s . c o m public static void init() { AWSCredentials credentials = null; try { // InputStream credentialsFile = Dynamodb.class.getResourceAsStream("awsSecuCredentials.properties"); InputStream credentialsFile = new FileInputStream("./awsSecuCredentials.properties"); credentials = new PropertiesCredentials(credentialsFile); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential file. ", e); } dynamoDB = new AmazonDynamoDBClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); dynamoDB.setRegion(usEast1); }