Skip to content

Commit c95f8b3

Browse files
author
Paul Ashton
committed
await send func
1 parent fba6295 commit c95f8b3

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

src/aws.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ async function getImageId(imageNameMatch) {
8484
}
8585
}
8686

87+
async function sendstart(command) {
88+
const ec2 = new EC2Client({region: process.env.AWS_REGION});
89+
90+
ec2.send(command, (err, data) => {
91+
if (err) {
92+
console.log(err, err.stack);
93+
core.error(`Error: ${err}`)
94+
throw err;
95+
} else {
96+
const ec2InstanceIds = data.Instances.map(x => x.InstanceId); //[0].InstanceId; pass all instances instead of just first id
97+
core.info(`AWS EC2 instance(s) ${ec2InstanceIds} is started`);
98+
return ec2InstanceIds;
99+
}
100+
});
101+
}
102+
87103
async function startEc2Instance(label, githubRegistrationToken) {
88104
const userData = buildUserDataScript(githubRegistrationToken, label);
89105

@@ -109,23 +125,25 @@ async function startEc2Instance(label, githubRegistrationToken) {
109125
}
110126
}
111127

112-
const ec2 = new EC2Client({region: process.env.AWS_REGION});
128+
//const ec2 = new EC2Client({region: process.env.AWS_REGION});
113129

114130
const runInstancesCommand = new RunInstancesCommand(params);
115131

116-
console.log("beforesend")
117-
await ec2.send(runInstancesCommand, (err, data) => {
118-
if (err) {
119-
console.log(err, err.stack);
120-
core.error(`AWS EC2 instance failed to start - error: ${err}`)
121-
throw err;
122-
} else {
123-
const ec2InstanceIds = data.Instances.map(x => x.InstanceId); //[0].InstanceId; pass all instances instead of just first id
124-
core.info(`AWS EC2 instance(s) ${ec2InstanceIds} is started`);
125-
return ec2InstanceIds;
126-
}
127-
});
128-
console.log("aftersend")
132+
//console.log("beforesend")
133+
const instanceIds = await sendstart(runInstancesCommand)
134+
return instanceIds
135+
// await ec2.send(runInstancesCommand, (err, data) => {
136+
// if (err) {
137+
// console.log(err, err.stack);
138+
// core.error(`AWS EC2 instance failed to start - error: ${err}`)
139+
// throw err;
140+
// } else {
141+
// const ec2InstanceIds = data.Instances.map(x => x.InstanceId); //[0].InstanceId; pass all instances instead of just first id
142+
// core.info(`AWS EC2 instance(s) ${ec2InstanceIds} is started`);
143+
// return ec2InstanceIds;
144+
// }
145+
// });
146+
// console.log("aftersend")
129147
}
130148

131149
async function terminateEc2Instance() {

0 commit comments

Comments
 (0)