-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp2.js
156 lines (120 loc) · 4.21 KB
/
app2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/***********
http://stackoverflow.com/questions/18484775/how-do-you-access-an-amazon-sns-post-body-with-express-node-js
http://aws.amazon.com/developers/access-keys/
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/frames.html#!AWS/SNS.html
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/frames.html
http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html
http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-examples.html
************/
var argv = require('optimist').argv;
console.log('(%d,%d)', argv.x, argv.y);
var AWS = require('aws-sdk');
var uuid = require('node-uuid');
AWS.config.loadFromPath('config.json');
/*
var s3 = new AWS.S3();
var bucketName = 'node-sdk-sample-' + uuid.v4();
var keyName = 'hello_world.txt';
s3.createBucket({Bucket: bucketName}, function() {
var params = {Bucket: bucketName, Key: keyName, Body: 'Hello World!'};
s3.putObject(params, function(err, data) {
if (err)
console.log(err)
else
console.log("Successfully uploaded data to " + bucketName + "/" + keyName);
});
});
s3.listBuckets(function(error, data) {
if (error) {
console.log(error); // error is Response.error
} else {
console.log(data); // data is Response.data
for (var index in data.Buckets) {
var bucket = data.Buckets[index];
console.log("Bucket: ", bucket.Name, ' : ', bucket.CreationDate);
}
}
});
var params = {'Bucket': 'myBucket', 'Key': 'myKey','Expires': 60};
var url = s3.getSignedUrl('getObject', params);
console.log("The URL is", url);
console.log(new Date());
*/
/*
var params = {Bucket: 'myBucket', Key: 'myImageFile.jpg'};
var file = require('fs').createWriteStream('/path/to/file.jpg');
s3.getObject(params).createReadStream().pipe(file);
s3.getObject(params).
on('httpData', function(chunk) { file.write(chunk); }).
on('httpDone', function() { file.end(); }).
send();
*/
/* SNS
AWS Free Tier availability:
1 million Mobile Push Notifications
100 SMS
1,000 email/email-JSON
100,000 HTTP/s
unlimited deliveries to SQS Queues
http://blog.matoski.com/articles/snssqs-for-node-js/
http://dev.classmethod.jp/cloud/amazonsns-http/
http://aws.amazon.com/documentation/sns/
http://docs.aws.amazon.com/sns/latest/dg/SNSMobilePush.html
http://docs.aws.amazon.com/sns/latest/dg/SendMessageToSQS.html
var sns = new AWS.SNS();
// subscribe
sns.Subscribe({topic: "topic", Protocol: "https"}, function (err, data) {
if (err) {
console.log(err); // an error occurred
} else {
console.log(data); // successful response - the body should be in the data
}
});
// publish example
sns.Publish({topic: "topic", message: "my message"}, function (err, data) {
if (err) {
console.log(err); // an error occurred
} else {
console.log(data); // successful response - the body should be in the data
}
});
*/
var ec2 = new AWS.EC2();
var params = {
//ImageId: 'ami-1624987f', // Amazon Linux AMI x86_64 EBS
ImageId: "ami-2d4aa444",
InstanceType: 't1.micro',
MinCount: 1, MaxCount: 1
};
// Create the instance
ec2.runInstances(params, function(err, data) {
if (err) { console.log("Could not create instance", err); return; }
var instanceId = data.Instances[0].InstanceId;
console.log("Created instance", instanceId);
// Add tags to the instance
params = {Resources: [instanceId], Tags: [
{Key: 'Name', Value: instanceName}
]};
ec2.createTags(params, function(err) {
console.log("Tagging instance", err ? "failure" : "success");
});
});
/*
app.post('/compressit',function(req,res) {
try{
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;
var orig_code = req.param("js");
var ast = jsp.parse(orig_code); // parse code and get the initial AST
ast = pro.ast_mangle(ast); // get a new AST with mangled names
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
ast = pro.ast_lift_variables(ast);
var final_code = pro.gen_code(ast,{inline_script:true});
res.send(final_code);
}
catch(err) {
res.send("Error:" +err.message);
}
});
Read more: http://jaspreetchahal.org/build-a-javascript-compressor-tool-using-nodejs-expressjs-jade-uglifyjs-tutorial/#ixzz2m4c00BYD
*/