Skip to content

Commit 03a644b

Browse files
author
Adam McKee
committed
aws and digitalocean
1 parent dc68c16 commit 03a644b

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

examples/aws_ec2.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { EC2Client, RunInstancesCommand } from '@aws-sdk/client-ec2'
2+
import { buildUserData } from '@eighty4/c2'
3+
4+
const userData = btoa(await buildUserData('cloud_init'))
5+
6+
const command = new RunInstancesCommand({
7+
ImageId: 'debian-12-arm64',
8+
InstanceType: 't2.micro',
9+
MinCount: 1,
10+
MaxCount: 1,
11+
InstanceName: 'my-instance-name',
12+
UserData: userData,
13+
})
14+
15+
const output = await new EC2Client({}).send(command)
16+
const instance = output.Instances[0]
17+
18+
console.log('created ec2 instance', instance.InstanceId, instance.Ipv4Address)

examples/digitalocean.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { buildUserData } from '@eighty4/c2'
2+
import DigitalOcean from 'dots-wrapper'
3+
4+
if (!process.env.DIGITALOCEAN_TOKEN) {
5+
throw new Error('DIGITALOCEAN_TOKEN env var is required')
6+
}
7+
8+
const userData = btoa(await buildUserData('cloud_init'))
9+
10+
const client = new DigitalOcean({
11+
token: process.env.DIGITALOCEAN_TOKEN,
12+
})
13+
14+
await client.droplets.create()

examples/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"dependencies": {
3-
"@linode/api-v4": "^0.138.0"
3+
"@aws-sdk/client-ec2": "^3.826.0",
4+
"@linode/api-v4": "^0.138.0",
5+
"dots-wrapper": "^3.12.0"
46
}
57
}

0 commit comments

Comments
 (0)