-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.txt
160 lines (139 loc) · 5.2 KB
/
test.txt
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
157
158
159
160
PRIMITIVE FUNCTIONALITY:
An application to spin up & spin down docker containers
FEATURES:
- Continoues integration and continoues development (Zero downtime)
- Cheaper compute using aws spot fleet
- SSH access (paid add-on)
- Easier deployments
PROBLEMS:
- TLS Certifictaes
- Domain names
// Import necessary classes from the AWS SDK
const { EC2Client, CreateFleetCommand } = require("@aws-sdk/client-ec2");
// (Optional) Configure the AWS client with your credentials
// Replace 'YOUR_ACCESS_KEY_ID' and 'YOUR_SECRET_ACCESS_KEY' with your actual credentials
const config = {
region: "REGION_NAME", // Replace with your desired AWS region
credentials: {
accessKeyId: 'YOUR_ACCESS_KEY_ID',
secretAccessKey: 'YOUR_SECRET_ACCESS_KEY'
}
};
const client = new EC2Client(config);
// Define the fleet launch configuration
const input = {
DryRun: true, // Set to 'false' to actually create the fleet
ClientToken: "unique_token_123", // Replace with a unique identifier
SpotOptions: {
AllocationStrategy: "lowest-price", // Choose your Spot Instance allocation strategy
InstanceInterruptionBehavior: "terminate", // Action to take on Spot Instance interruption
MinTargetCapacity: 2, // Minimum number of instances in the fleet
MaxTotalPrice: "0.10", // Maximum hourly price for Spot Instances (adjust as needed)
},
// (Optional) Configure On-Demand Options if needed
// OnDemandOptions: {
// ... similar structure to SpotOptions ...
// },
ExcessCapacityTerminationPolicy: "no-termination", // Policy for handling excess instances
LaunchTemplateConfigs: [
{
LaunchTemplateName: "your-launch-template-name", // Replace with your launch template name
WeightedCapacity: 1 // Allocate 100% of instances from this launch template
}
]
};
// Create the EC2 fleet using the configured client and input
const run = async () => {
try {
const command = new CreateFleetCommand(input);
await client.send(command);
console.log("Fleet creation request sent successfully!");
} catch (error) {
console.error("Error creating fleet:", error);
}
};
run();
//////////////////// ------------------------------------ //////////////
// Content-Type: multipart/mixed; boundary="//"
// MIME-Version: 1.0
// --//
// Content-Type: text/cloud-config; charset="us-ascii"
// MIME-Version: 1.0
// Content-Transfer-Encoding: 7bit
// Content-Disposition: attachment; filename="cloud-config.txt"
// #cloud-config
// cloud_final_modules:
// - [scripts-user, always]
// --//
// Content-Type: text/x-shellscript; charset="us-ascii"
// MIME-Version: 1.0
// Content-Transfer-Encoding: 7bit
// Content-Disposition: attachment; filename="userdata.txt"
// sudo docker pull axnjr/ignition_wssd:1
// sudo docker run -e VALIDATION_TOKEN=${key as string} -p 3000:3000 axnjr/ignition_wssd:1
/**
* sudo rm -rf /var/lib/cloud/*
sudo cloud-init init
sudo cloud-init modules -m final
*/
/**
* const instanceParams = {
ImageId: 'ami-05295b6e6c790593e', // Replace with the AMI ID you want to use
InstanceType: 't2.micro',
KeyName: 'WSSSharedClusterECS',
MinCount: 1,
MaxCount: 1,
UserData: Buffer.from(userDataScript).toString('base64'), // Encode your user data script
};
const ec2 = new AWS.EC2({
region: "ap-south-1",
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
});
try {
// @ts-ignore
const data = await ec2.runInstances({
...instanceParams,
SecurityGroupIds:["sg-0ff0a8d2ad83577c5"],
SubnetId:"subnet-07d9a1a6ce4f3d551",
BlockDeviceMappings:{
SnapShotId:"snap-0be91b48311219ca8",
VirtualName:"ignitionwssdfromtemplate"
}
}).promise();
if(data.Instances) {
console.log(data.Instances[0].InstanceId)
return new NextResponse(JSON.stringify({
success: true,
data: data.Instances[0].InstanceId
}))
}
} catch (error) {
console.log(error)
return new NextResponse("ERROR OCCURED !!")
}
*/
const createGroupCommand = new CreateSecurityGroupCommand({
GroupName:"computeflow_security_group",
Description:"Security group to allow all traffic to all ports"
});
const createGroupResponse = await ec2.send(createGroupCommand);
const securityGroupId = createGroupResponse.GroupId;
console.log(`Security Group Created: ${securityGroupId}`);
// Authorize inbound traffic
const ingressParams = {
GroupId: securityGroupId,
IpPermissions: [
{
IpProtocol: '-1', // -1 means all protocols
IpRanges: [
{
CidrIp: '0.0.0.0/0', // Allow all IP addresses
},
],
},
],
};
const ingressCommand = new AuthorizeSecurityGroupIngressCommand(ingressParams);
await ec2.send(ingressCommand);
console.log(`Inbound traffic allowed for Security Group: ${securityGroupId}`);