List of usage examples for com.amazonaws.auth PropertiesCredentials PropertiesCredentials
public PropertiesCredentials(InputStream inputStream) throws IOException
From source file:com.lvl6.mobsters.dynamo.setup.TransactionExamples.java
License:Open Source License
public TransactionExamples() { AWSCredentials credentials;/*from w ww.j ava2s. c om*/ try { credentials = new PropertiesCredentials( TransactionExamples.class.getResourceAsStream("AwsCredentials.properties")); } catch (IOException e) { throw new RuntimeException(e); } dynamodb = new AmazonDynamoDBClient(credentials); dynamodb.setEndpoint(DYNAMODB_ENDPOINT); txManager = new TransactionManager(dynamodb, TX_TABLE_NAME, TX_IMAGES_TABLE_NAME); }
From source file:com.makariev.dynamodb.config.aws.DynamoDbContext.java
License:Open Source License
public DynamoDbContext() throws IOException { final AWSCredentials credentials = new PropertiesCredentials( DynamoDbContext.class.getResourceAsStream("/AwsCredentials.properties")); // final AWSCredentials credentials = new BasicAWSCredentials("", ""); this.dynamoDb = new AmazonDynamoDBClient(credentials); final String endpoint = System.getProperty("dynamodb.endpoint"); this.dynamoDb.setEndpoint(String.format(endpoint)); this.mapper = new DynamoDBMapper(this.dynamoDb); }
From source file:com.mycompany.rproject.runnableClass.java
public static void use() throws IOException { AWSCredentials awsCreds = new PropertiesCredentials( new File("/Users/paulamontojo/Desktop/AwsCredentials.properties")); AmazonSQS sqs = new AmazonSQSClient(awsCreds); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2);//from www . j a v a2 s . c o m String myQueueUrl = "https://sqs.us-west-2.amazonaws.com/711690152696/MyQueue"; System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); while (messages.isEmpty()) { messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); } String messageRecieptHandle = messages.get(0).getReceiptHandle(); String a = messages.get(0).getBody(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); //aqui opero y cuando acabe llamo para operar el siguiente. String n = ""; String dbName = "mydb"; String userName = "pmontojo"; String password = "pmontojo"; String hostname = "mydb.cued7orr1q2t.us-west-2.rds.amazonaws.com"; String port = "3306"; String jdbcUrl = "jdbc:mysql://" + hostname + ":" + port + "/" + dbName + "?user=" + userName + "&password=" + password; Connection conn = null; Statement setupStatement = null; Statement readStatement = null; ResultSet resultSet = null; String results = ""; int numresults = 0; String statement = null; try { conn = DriverManager.getConnection(jdbcUrl); setupStatement = conn.createStatement(); String insertUrl = "select video_name from metadata where id = " + a + ";"; String checkUrl = "select url from metadata where id = " + a + ";"; ResultSet rs = setupStatement.executeQuery(insertUrl); rs.next(); System.out.println("este es el resultdo " + rs.getString(1)); String names = rs.getString(1); ResultSet ch = setupStatement.executeQuery(checkUrl); ch.next(); System.out.println("este es la url" + ch.getString(1)); String urli = ch.getString(1); while (urli == null) { ResultSet sh = setupStatement.executeQuery(checkUrl); sh.next(); System.out.println("este es la url" + sh.getString(1)); urli = sh.getString(1); } setupStatement.close(); AmazonS3 s3Client = new AmazonS3Client(awsCreds); S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, names)); IOUtils.copy(object.getObjectContent(), new FileOutputStream(new File("/Users/paulamontojo/Desktop/download.avi"))); putOutput(); write(); putInDb(sbu.toString(), a); } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } finally { System.out.println("Closing the connection."); if (conn != null) try { conn.close(); } catch (SQLException ignore) { } } use(); }
From source file:com.mycompany.rproject.runnableClass.java
public static void putInDb(String s, String id) throws IOException { AWSCredentials credentials = new PropertiesCredentials( new File("/Users/paulamontojo/Desktop/AwsCredentials.properties")); dynamoDBClient = new AmazonDynamoDBClient(new STSSessionCredentialsProvider(credentials)); dynamoDBClient.setRegion(Region.getRegion(Regions.US_WEST_2)); createTable();/* w w w. j a va 2 s. c om*/ // Describe our new table describeTable(); // Add some items putItem(newItem(id, "url", s)); }
From source file:com.netflix.servo.tag.aws.AwsInjectableTag.java
License:Apache License
static String getAutoScaleGroup() { try {/*w w w. j a v a 2 s .c o m*/ String credFileProperty = System.getProperties().getProperty(AwsPropertyKeys.awsCredentialsFile); AWSCredentials credentials; if (credFileProperty != null) { credentials = new PropertiesCredentials(new File(credFileProperty)); } else { credentials = new DefaultAWSCredentialsProviderChain().getCredentials(); } AmazonAutoScaling autoScalingClient = new AmazonAutoScalingClient(credentials); return autoScalingClient .describeAutoScalingInstances( new DescribeAutoScalingInstancesRequest().withInstanceIds(getInstanceId())) .getAutoScalingInstances().get(0).getAutoScalingGroupName(); } catch (Exception e) { log.error("Unable to get ASG name.", e); return undefined; } }
From source file:com.onemenu.server.util.awsnotification.SNSMobilePush.java
License:Open Source License
public static void pushIOSNotification(String message, String deviceToken, Map<String, Object> customData, int badge) throws IOException { AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( SNSMobilePush.class.getClassLoader().getResourceAsStream("AwsCredentials.properties"))); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); if (logger.isDebugEnabled()) { logger.debug("===========================================\n"); logger.debug("Getting Started with Amazon SNS IOS"); logger.debug("===========================================\n"); }/*from w w w . jav a 2 s . c o m*/ try { SNSMobilePush push = new SNSMobilePush(sns); String applicationName = ConfigCache.getValue(ConfigKey.APPLICATION_NAME, "One-Menu"); String _message = MessageGenerator.getAppleMessage(message, null, badge, customData); boolean isSandBox = Boolean.parseBoolean(ConfigCache.getValue(ConfigKey.IS_SAND_BOX, "true")); Platform platform = null; String Certificate = null; String Private_Key = null; if (isSandBox) { platform = Platform.APNS_SANDBOX; Certificate = S_Certificate; Private_Key = S_Private_Key; } else { platform = Platform.APNS; Certificate = P_Certificate; Private_Key = P_Private_Key; } push.snsClientWrapper.notification(platform, Certificate, Private_Key, deviceToken, applicationName, attributesMap, _message); } catch (AmazonServiceException ase) { logger.error("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, but was rejected with an error response for some reason."); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { logger.error("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SNS, such as not " + "being able to access the network."); logger.error("Error Message: " + ace.getMessage()); } }
From source file:com.onemenu.server.util.awsnotification.SNSMobilePush.java
License:Open Source License
public static void pushAndroidNotification(String message, String deviceToken, Map<String, Object> customData) throws IOException { AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( SNSMobilePush.class.getClassLoader().getResourceAsStream("AwsCredentials.properties"))); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); if (logger.isDebugEnabled()) { logger.debug("===========================================\n"); logger.debug("Getting Started with Amazon SNS android"); logger.debug("===========================================\n"); }// ww w .ja va 2s.co m try { SNSMobilePush push = new SNSMobilePush(sns); String applicationName = ConfigCache.getValue(ConfigKey.APPLICATION_NAME, "One-Menu"); String serverAPIKey = ""; String _message = MessageGenerator.getSampleAndroidMessage("NewOrder", message, customData); push.snsClientWrapper.notification(Platform.GCM, "", serverAPIKey, deviceToken, applicationName, attributesMap, _message); } catch (AmazonServiceException ase) { logger.error("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, but was rejected with an error response for some reason."); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { logger.error("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SNS, such as not " + "being able to access the network."); logger.error("Error Message: " + ace.getMessage()); } }
From source file:com.onemenu.server.util.awsnotification.SNSMobilePush.java
License:Open Source License
public static void main(String[] args) throws IOException { /*//from w ww. j a va 2 s.c o m * TODO: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this sample. * http://aws.amazon.com/security-credentials */ AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( SNSMobilePush.class.getClassLoader().getResourceAsStream("AwsCredentials.properties"))); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); System.out.println("===========================================\n"); System.out.println("Getting Started with Amazon SNS"); System.out.println("===========================================\n"); try { SNSMobilePush sample = new SNSMobilePush(sns); sample.demoAppleSandboxAppNotification(); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, 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 SNS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.oracle.coherence.cloud.amazon.EC2AddressProvider.java
License:Open Source License
/** * This method determines what credentials to use for EC2 authentication. * /* www . j av a 2 s.c o m*/ * @return the {@link AWSCredentials} * * @throws IOException if reading the property file fails */ protected AWSCredentials determineCredentials() throws IOException { String accessKey = System.getProperty("tangosol.coherence.ec2addressprovider.accesskey"); String secretKey = System.getProperty("tangosol.coherence.ec2addressprovider.secretkey"); if ((accessKey == null) || (secretKey == null) || accessKey.equals("") || secretKey.equals("")) { if (logger.isLoggable(Level.CONFIG)) { logger.log(Level.CONFIG, "No EC2AddressProvider credential system properties provided."); } // Retrieve the credentials from a properties resource instead. String propertyResource = System.getProperty("tangosol.coherence.ec2addressprovider.propertyfile", "AwsCredentials.properties"); InputStream stream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(propertyResource); if (stream != null) { return new PropertiesCredentials(stream); } else { throw new RuntimeException( "The EC2AddressProvider could not find any credentials, neither as system properties, nor as " + propertyResource + " resource"); } } else { return new BasicAWSCredentials(accessKey, secretKey); } }
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 va2s . co 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); }