Skip to content

Commit 0d98d4e

Browse files
committed
mesh
1 parent 153f664 commit 0d98d4e

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed

rds.tf

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource "aws_db_instance" "default" {
2+
allocated_storage = 20
3+
storage_type = "gp2"
4+
engine = "mysql"
5+
engine_version = "5.7"
6+
instance_class = "db.t2.micro"
7+
name = "myRDSdb"
8+
username = "foo"
9+
password = "foobarbaz"
10+
parameter_group_name = "default.mysql5.7"
11+
12+
13+
#backup_window = "09:01-11:00"
14+
#backup_retention_period = 7
15+
16+
}

s3.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "aws_s3_bucket" "b" {
2+
bucket = "S3B_181355"
3+
acl = "public-read"
4+
5+
tags = {
6+
Name = "My bucket"
7+
Environment = "Dev"
8+
}
9+
}

sqs.tf

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_sqs_queue" "q" {
2+
name = "examplequeue"
3+
}
4+
5+
resource "aws_sqs_queue_policy" "test" {
6+
queue_url = aws_sqs_queue.q.id
7+
8+
policy = <<POLICY
9+
{
10+
"Version": "2012-10-17",
11+
"Id": "sqspolicy",
12+
"Statement": [
13+
{
14+
"Effect": "Allow",
15+
"Principal": "*",
16+
"Action": "*",
17+
"Resource": "*"
18+
}
19+
]
20+
}
21+
POLICY
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Cl {
2+
private static Connection getRemoteConnection() {
3+
if (System.getenv("RDS_HOSTNAME") != null) {
4+
try {
5+
Class.forName("org.postgresql.Driver");
6+
String dbName = "myRDSdb";
7+
String userName = "foo";
8+
String password = "foobarbaz";
9+
String hostname = System.getenv("RDS_HOSTNAME");
10+
String port = System.getenv("RDS_PORT");
11+
String jdbcUrl = "jdbc:postgresql://" + hostname + ":" + port + "/" + dbName + "?user=" + userName + "&password=" + password;
12+
logger.trace("Getting remote connection with connection string from environment variables.");
13+
Connection con = DriverManager.getConnection(jdbcUrl);
14+
logger.info("Remote connection successful.");
15+
return con;
16+
}
17+
catch (ClassNotFoundException e) { logger.warn(e.toString());}
18+
catch (SQLException e) { logger.warn(e.toString());}
19+
}
20+
return null;
21+
}
22+
23+
String saveInvoiceData(string data, int id){
24+
try{
25+
Connection con = getRemoteConnection();
26+
Statement stmt = con.createStatement();
27+
rs = stmt.executeQuery("UPDATE INVOICE SET data = '" + data + "' WHERE ID = " + id);
28+
return rs.getString("Id");
29+
} catch (Exception exc){
30+
//
31+
}
32+
return null;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import com.amazonaws.AmazonServiceException;
2+
import com.amazonaws.SdkClientException;
3+
import com.amazonaws.regions.Regions;
4+
import com.amazonaws.services.s3.AmazonS3;
5+
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
6+
import com.amazonaws.services.s3.model.ObjectMetadata;
7+
import com.amazonaws.services.s3.model.PutObjectRequest;
8+
9+
import java.io.File;
10+
import java.io.IOException;
11+
12+
public class UploadObject {
13+
14+
public static void saveCC(string creditCardNumber) throws IOException {
15+
Regions clientRegion = Regions.DEFAULT_REGION;
16+
String bucketName = "S3B_181355";
17+
String stringObjKeyName = "XKIB5WDJHVGINH8YOZFC";
18+
19+
try {
20+
21+
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
22+
.withRegion(clientRegion)
23+
.build();
24+
25+
26+
27+
// Upload a text string with cc as a new object
28+
s3Client.putObject(bucketName, stringObjKeyName, creditCardNumber);
29+
30+
31+
} catch (AmazonServiceException e) {
32+
// The call was transmitted successfully, but Amazon S3 couldn't process
33+
// it, so it returned an error response.
34+
e.printStackTrace();
35+
} catch (SdkClientException e) {
36+
// Amazon S3 couldn't be contacted for a response, or the client
37+
// couldn't parse the response from Amazon S3.
38+
e.printStackTrace();
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package messageQ;
2+
3+
import com.amazonaws.services.sqs.AmazonSQSClientBuilder;
4+
import com.amazonaws.services.sqs.model.AmazonSQSException;
5+
import com.amazonaws.services.sqs.model.SendMessageBatchRequest;
6+
7+
import java.sql.Connection;
8+
import java.sql.DriverManager;
9+
import java.sql.SQLException;
10+
import java.sql.Statement;
11+
import java.sql.ResultSet;
12+
13+
class DoLogic{
14+
15+
void execute() {
16+
List<Message> list = read();
17+
if (list != null && list.count() > 0) {
18+
getId(list[0]);
19+
}
20+
}
21+
22+
List<Message> read(){
23+
try{
24+
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
25+
List<Message> messages = sqs.receiveMessage("aws_sqs_queue.q.id").getMessages();
26+
return messages;
27+
} catch (Exception ex){
28+
//
29+
}
30+
return null;
31+
}
32+
33+
String getId(string data){
34+
try{
35+
Connection con=DriverManager.getConnection("jdbc:mysql://db.com:3306/core", USER, PASS);
36+
Statement stmt = con.createStatement();
37+
rs = stmt.executeQuery("SELECT id FROM t where data = '" + data + "'");
38+
return rs.getString("Id");
39+
} catch (Exception exc){
40+
//
41+
}
42+
return null;
43+
}
44+
}

0 commit comments

Comments
 (0)