0
# Compute Services
1
2
Comprehensive compute capabilities including virtual machines (EC2), serverless functions (Lambda), container orchestration (ECS/EKS), and auto-scaling services.
3
4
## Capabilities
5
6
### EC2 - Virtual Machines
7
8
Elastic Compute Cloud provides scalable virtual machine instances with full control over the computing environment.
9
10
```typescript { .api }
11
/**
12
* EC2 virtual machine instance
13
*/
14
class ec2.Instance extends pulumi.CustomResource {
15
constructor(name: string, args: ec2.InstanceArgs, opts?: pulumi.CustomResourceOptions);
16
17
/** Amazon Machine Image (AMI) ID */
18
readonly ami: pulumi.Output<string>;
19
/** Instance type (e.g., "t3.micro", "m5.large") */
20
readonly instanceType: pulumi.Output<string>;
21
/** Availability zone where instance is placed */
22
readonly availabilityZone: pulumi.Output<string>;
23
/** Private IP address */
24
readonly privateIp: pulumi.Output<string>;
25
/** Public IP address (if in public subnet) */
26
readonly publicIp: pulumi.Output<string>;
27
/** Public DNS name */
28
readonly publicDns: pulumi.Output<string>;
29
/** Instance state (running, stopped, etc.) */
30
readonly instanceState: pulumi.Output<string>;
31
/** Security group IDs */
32
readonly securityGroups: pulumi.Output<string[]>;
33
/** Subnet ID where instance is placed */
34
readonly subnetId: pulumi.Output<string>;
35
/** VPC ID */
36
readonly vpcSecurityGroupIds: pulumi.Output<string[]>;
37
/** Resource tags */
38
readonly tags: pulumi.Output<{[key: string]: string}>;
39
}
40
41
interface ec2.InstanceArgs {
42
/** AMI ID to launch */
43
ami: pulumi.Input<string>;
44
/** Instance type */
45
instanceType: pulumi.Input<string>;
46
/** Availability zone (optional) */
47
availabilityZone?: pulumi.Input<string>;
48
/** Subnet ID (required for VPC instances) */
49
subnetId?: pulumi.Input<string>;
50
/** Security group IDs */
51
vpcSecurityGroupIds?: pulumi.Input<pulumi.Input<string>[]>;
52
/** Key pair name for SSH access */
53
keyName?: pulumi.Input<string>;
54
/** User data script */
55
userData?: pulumi.Input<string>;
56
/** IAM instance profile */
57
iamInstanceProfile?: pulumi.Input<string>;
58
/** Enable detailed monitoring */
59
monitoring?: pulumi.Input<boolean>;
60
/** Associate public IP address */
61
associatePublicIpAddress?: pulumi.Input<boolean>;
62
/** Root block device configuration */
63
rootBlockDevice?: pulumi.Input<ec2.InstanceRootBlockDevice>;
64
/** Additional EBS block devices */
65
ebsBlockDevices?: pulumi.Input<pulumi.Input<ec2.InstanceEbsBlockDevice>[]>;
66
/** Resource tags */
67
tags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
68
}
69
70
/**
71
* Query existing EC2 instances
72
*/
73
function ec2.getInstance(args: ec2.GetInstanceArgs): Promise<ec2.GetInstanceResult>;
74
75
interface ec2.GetInstanceArgs {
76
/** Instance ID */
77
instanceId?: string;
78
/** Instance tags filter */
79
instanceTags?: {[key: string]: string};
80
/** Additional filters */
81
filters?: ec2.GetInstanceFilter[];
82
}
83
84
interface ec2.GetInstanceResult {
85
readonly ami: string;
86
readonly instanceType: string;
87
readonly privateIp: string;
88
readonly publicIp: string;
89
readonly securityGroups: string[];
90
readonly subnetId: string;
91
readonly tags: {[key: string]: string};
92
}
93
```
94
95
**Usage Examples:**
96
97
```typescript
98
// Create a basic EC2 instance
99
const instance = new aws.ec2.Instance("web-server", {
100
ami: "ami-0c55b159cbfafe1d0", // Amazon Linux 2
101
instanceType: "t3.micro",
102
keyName: "my-key-pair",
103
userData: `#!/bin/bash
104
yum update -y
105
yum install -y httpd
106
systemctl start httpd
107
systemctl enable httpd
108
`,
109
tags: {
110
Name: "WebServer",
111
Environment: "production"
112
}
113
});
114
115
// Create instance in specific subnet with security group
116
const webInstance = new aws.ec2.Instance("web-instance", {
117
ami: ami.id,
118
instanceType: "t3.small",
119
subnetId: publicSubnet.id,
120
vpcSecurityGroupIds: [webSecurityGroup.id],
121
associatePublicIpAddress: true,
122
rootBlockDevice: {
123
volumeType: "gp3",
124
volumeSize: 20,
125
encrypted: true
126
}
127
});
128
129
// Query existing instances
130
const existingInstance = await aws.ec2.getInstance({
131
filters: [
132
{ name: "tag:Environment", values: ["production"] },
133
{ name: "instance-state-name", values: ["running"] }
134
]
135
});
136
```
137
138
### Lambda - Serverless Functions
139
140
AWS Lambda runs code without managing servers, automatically scaling and charging only for compute time used.
141
142
```typescript { .api }
143
/**
144
* Lambda function resource
145
*/
146
class lambda.Function extends pulumi.CustomResource {
147
constructor(name: string, args: lambda.FunctionArgs, opts?: pulumi.CustomResourceOptions);
148
149
/** Function ARN */
150
readonly arn: pulumi.Output<string>;
151
/** Function name */
152
readonly functionName: pulumi.Output<string>;
153
/** Runtime environment */
154
readonly runtime: pulumi.Output<string>;
155
/** Handler function entry point */
156
readonly handler: pulumi.Output<string>;
157
/** Function code package */
158
readonly code: pulumi.Output<lambda.FunctionCode>;
159
/** Execution role ARN */
160
readonly role: pulumi.Output<string>;
161
/** Memory allocation in MB */
162
readonly memorySize: pulumi.Output<number>;
163
/** Timeout in seconds */
164
readonly timeout: pulumi.Output<number>;
165
/** Environment variables */
166
readonly environment: pulumi.Output<lambda.FunctionEnvironment>;
167
/** VPC configuration */
168
readonly vpcConfig: pulumi.Output<lambda.FunctionVpcConfig>;
169
}
170
171
interface lambda.FunctionArgs {
172
/** Function name */
173
functionName?: pulumi.Input<string>;
174
/** Runtime (e.g., "nodejs18.x", "python3.9", "java11") */
175
runtime: pulumi.Input<string>;
176
/** Handler entry point */
177
handler: pulumi.Input<string>;
178
/** Function code */
179
code: pulumi.Input<lambda.FunctionCode>;
180
/** IAM role ARN for execution */
181
role: pulumi.Input<string>;
182
/** Memory size in MB (128-10240) */
183
memorySize?: pulumi.Input<number>;
184
/** Timeout in seconds (1-900) */
185
timeout?: pulumi.Input<number>;
186
/** Environment variables */
187
environment?: pulumi.Input<lambda.FunctionEnvironment>;
188
/** VPC configuration for private resources */
189
vpcConfig?: pulumi.Input<lambda.FunctionVpcConfig>;
190
/** Dead letter queue configuration */
191
deadLetterConfig?: pulumi.Input<lambda.FunctionDeadLetterConfig>;
192
/** Function description */
193
description?: pulumi.Input<string>;
194
/** Resource tags */
195
tags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
196
}
197
198
interface lambda.FunctionCode {
199
/** S3 bucket containing code */
200
s3Bucket?: pulumi.Input<string>;
201
/** S3 object key */
202
s3Key?: pulumi.Input<string>;
203
/** ZIP file content (base64 encoded) */
204
zipFile?: pulumi.Input<string>;
205
}
206
207
interface lambda.FunctionEnvironment {
208
/** Environment variable map */
209
variables?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
210
}
211
```
212
213
**Usage Examples:**
214
215
```typescript
216
// Create Lambda function with inline code
217
const helloFunction = new aws.lambda.Function("hello", {
218
runtime: "nodejs18.x",
219
handler: "index.handler",
220
role: lambdaRole.arn,
221
code: new pulumi.asset.AssetArchive({
222
"index.js": new pulumi.asset.StringAsset(`
223
exports.handler = async (event) => {
224
return {
225
statusCode: 200,
226
body: JSON.stringify('Hello from Lambda!')
227
};
228
};
229
`)
230
})
231
});
232
233
// Lambda function with S3 code and environment variables
234
const apiFunction = new aws.lambda.Function("api-handler", {
235
functionName: "api-handler",
236
runtime: "python3.9",
237
handler: "app.lambda_handler",
238
role: lambdaRole.arn,
239
code: {
240
s3Bucket: codeBucket.bucket,
241
s3Key: "api-handler.zip"
242
},
243
memorySize: 256,
244
timeout: 30,
245
environment: {
246
variables: {
247
TABLE_NAME: dynamoTable.name,
248
REGION: "us-west-2"
249
}
250
},
251
vpcConfig: {
252
subnetIds: privateSubnets.map(s => s.id),
253
securityGroupIds: [lambdaSecurityGroup.id]
254
}
255
});
256
```
257
258
### ECS - Container Service
259
260
Elastic Container Service runs Docker containers with managed cluster infrastructure.
261
262
```typescript { .api }
263
/**
264
* ECS cluster for running containers
265
*/
266
class ecs.Cluster extends pulumi.CustomResource {
267
constructor(name: string, args?: ecs.ClusterArgs, opts?: pulumi.CustomResourceOptions);
268
269
/** Cluster ARN */
270
readonly arn: pulumi.Output<string>;
271
/** Cluster name */
272
readonly name: pulumi.Output<string>;
273
/** Capacity providers */
274
readonly capacityProviders: pulumi.Output<string[]>;
275
/** Default capacity provider strategy */
276
readonly defaultCapacityProviderStrategy: pulumi.Output<ecs.ClusterDefaultCapacityProviderStrategy[]>;
277
}
278
279
/**
280
* ECS service for running tasks
281
*/
282
class ecs.Service extends pulumi.CustomResource {
283
constructor(name: string, args: ecs.ServiceArgs, opts?: pulumi.CustomResourceOptions);
284
285
/** Service ARN */
286
readonly arn: pulumi.Output<string>;
287
/** Service name */
288
readonly name: pulumi.Output<string>;
289
/** Cluster ARN */
290
readonly cluster: pulumi.Output<string>;
291
/** Task definition ARN */
292
readonly taskDefinition: pulumi.Output<string>;
293
/** Desired task count */
294
readonly desiredCount: pulumi.Output<number>;
295
/** Load balancer configuration */
296
readonly loadBalancers: pulumi.Output<ecs.ServiceLoadBalancer[]>;
297
}
298
299
/**
300
* ECS task definition
301
*/
302
class ecs.TaskDefinition extends pulumi.CustomResource {
303
constructor(name: string, args: ecs.TaskDefinitionArgs, opts?: pulumi.CustomResourceOptions);
304
305
/** Task definition ARN */
306
readonly arn: pulumi.Output<string>;
307
/** Family name */
308
readonly family: pulumi.Output<string>;
309
/** Container definitions */
310
readonly containerDefinitions: pulumi.Output<string>;
311
/** Launch type compatibility */
312
readonly requiresCompatibilities: pulumi.Output<string[]>;
313
/** CPU allocation */
314
readonly cpu: pulumi.Output<string>;
315
/** Memory allocation */
316
readonly memory: pulumi.Output<string>;
317
/** Network mode */
318
readonly networkMode: pulumi.Output<string>;
319
/** Task execution role ARN */
320
readonly executionRoleArn: pulumi.Output<string>;
321
/** Task role ARN */
322
readonly taskRoleArn: pulumi.Output<string>;
323
}
324
```
325
326
### EKS - Kubernetes Service
327
328
Elastic Kubernetes Service provides managed Kubernetes clusters.
329
330
```typescript { .api }
331
/**
332
* EKS cluster
333
*/
334
class eks.Cluster extends pulumi.CustomResource {
335
constructor(name: string, args: eks.ClusterArgs, opts?: pulumi.CustomResourceOptions);
336
337
/** Cluster ARN */
338
readonly arn: pulumi.Output<string>;
339
/** Cluster name */
340
readonly name: pulumi.Output<string>;
341
/** Kubernetes version */
342
readonly version: pulumi.Output<string>;
343
/** Cluster endpoint URL */
344
readonly endpoint: pulumi.Output<string>;
345
/** Service role ARN */
346
readonly roleArn: pulumi.Output<string>;
347
/** VPC configuration */
348
readonly vpcConfig: pulumi.Output<eks.ClusterVpcConfig>;
349
/** Certificate authority data */
350
readonly certificateAuthority: pulumi.Output<eks.ClusterCertificateAuthority>;
351
}
352
353
/**
354
* EKS node group
355
*/
356
class eks.NodeGroup extends pulumi.CustomResource {
357
constructor(name: string, args: eks.NodeGroupArgs, opts?: pulumi.CustomResourceOptions);
358
359
/** Node group ARN */
360
readonly arn: pulumi.Output<string>;
361
/** Cluster name */
362
readonly clusterName: pulumi.Output<string>;
363
/** Node group name */
364
readonly nodeGroupName: pulumi.Output<string>;
365
/** Instance types */
366
readonly instanceTypes: pulumi.Output<string[]>;
367
/** Scaling configuration */
368
readonly scalingConfig: pulumi.Output<eks.NodeGroupScalingConfig>;
369
/** Node role ARN */
370
readonly nodeRoleArn: pulumi.Output<string>;
371
/** Subnet IDs */
372
readonly subnetIds: pulumi.Output<string[]>;
373
}
374
```
375
376
### Auto Scaling
377
378
Automatically adjust compute capacity based on demand.
379
380
```typescript { .api }
381
/**
382
* Auto Scaling Group
383
*/
384
class autoscaling.Group extends pulumi.CustomResource {
385
constructor(name: string, args: autoscaling.GroupArgs, opts?: pulumi.CustomResourceOptions);
386
387
/** Auto Scaling Group ARN */
388
readonly arn: pulumi.Output<string>;
389
/** Group name */
390
readonly name: pulumi.Output<string>;
391
/** Launch template specification */
392
readonly launchTemplate: pulumi.Output<autoscaling.GroupLaunchTemplate>;
393
/** Minimum size */
394
readonly minSize: pulumi.Output<number>;
395
/** Maximum size */
396
readonly maxSize: pulumi.Output<number>;
397
/** Desired capacity */
398
readonly desiredCapacity: pulumi.Output<number>;
399
/** VPC zone identifiers (subnet IDs) */
400
readonly vpcZoneIdentifiers: pulumi.Output<string[]>;
401
/** Health check type */
402
readonly healthCheckType: pulumi.Output<string>;
403
/** Target group ARNs */
404
readonly targetGroupArns: pulumi.Output<string[]>;
405
}
406
407
/**
408
* Launch template for Auto Scaling
409
*/
410
class ec2.LaunchTemplate extends pulumi.CustomResource {
411
constructor(name: string, args?: ec2.LaunchTemplateArgs, opts?: pulumi.CustomResourceOptions);
412
413
/** Launch template ARN */
414
readonly arn: pulumi.Output<string>;
415
/** Template name */
416
readonly name: pulumi.Output<string>;
417
/** Latest version number */
418
readonly latestVersion: pulumi.Output<number>;
419
/** Image ID */
420
readonly imageId: pulumi.Output<string>;
421
/** Instance type */
422
readonly instanceType: pulumi.Output<string>;
423
/** User data */
424
readonly userData: pulumi.Output<string>;
425
/** Security group IDs */
426
readonly securityGroupNames: pulumi.Output<string[]>;
427
}
428
```
429
430
**Usage Examples:**
431
432
```typescript
433
// ECS cluster with Fargate service
434
const cluster = new aws.ecs.Cluster("app-cluster", {
435
capacityProviders: ["FARGATE", "FARGATE_SPOT"]
436
});
437
438
const taskDefinition = new aws.ecs.TaskDefinition("app-task", {
439
family: "app",
440
requiresCompatibilities: ["FARGATE"],
441
networkMode: "awsvpc",
442
cpu: "256",
443
memory: "512",
444
executionRoleArn: taskExecutionRole.arn,
445
containerDefinitions: JSON.stringify([{
446
name: "app",
447
image: "nginx:latest",
448
portMappings: [{
449
containerPort: 80,
450
protocol: "tcp"
451
}]
452
}])
453
});
454
455
const service = new aws.ecs.Service("app-service", {
456
cluster: cluster.id,
457
taskDefinition: taskDefinition.arn,
458
desiredCount: 2,
459
launchType: "FARGATE",
460
networkConfiguration: {
461
subnets: privateSubnets.map(s => s.id),
462
securityGroups: [appSecurityGroup.id]
463
}
464
});
465
466
// Auto Scaling Group with Launch Template
467
const launchTemplate = new aws.ec2.LaunchTemplate("web-template", {
468
imageId: ami.id,
469
instanceType: "t3.micro",
470
keyName: "my-key",
471
vpcSecurityGroupIds: [webSecurityGroup.id],
472
userData: Buffer.from(userData).toString('base64')
473
});
474
475
const asg = new aws.autoscaling.Group("web-asg", {
476
launchTemplate: {
477
id: launchTemplate.id,
478
version: "$Latest"
479
},
480
minSize: 1,
481
maxSize: 5,
482
desiredCapacity: 2,
483
vpcZoneIdentifiers: publicSubnets.map(s => s.id),
484
targetGroupArns: [targetGroup.arn],
485
healthCheckType: "ELB"
486
});
487
```