@studion/infra-code-blocks 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/components/ec2-ssm-connect.js +30 -18
- package/dist/components/web-server.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -284,6 +284,34 @@ export type WebServerArgs = {
|
|
|
284
284
|
};
|
|
285
285
|
```
|
|
286
286
|
|
|
287
|
+
#### Exec into running ECS task
|
|
288
|
+
|
|
289
|
+
**Prerequisites**
|
|
290
|
+
|
|
291
|
+
1. Install the [Session Manager plugin](https://docs.aws.amazon.com/systems-manager/latest/userguide/install-plugin-macos-overview.html#install-plugin-macos)
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
$ brew install --cask session-manager-plugin
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
2. Install jq
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
$ brew install jq
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
In order to exec into running ECS container run the following command:
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
aws ecs execute-command \
|
|
307
|
+
--cluster CLUSTER_NAME \
|
|
308
|
+
--task $(aws ecs list-tasks --cluster CLUSTER_NAME --family TASK_FAMILY_NAME | jq -r '.taskArns[0] | split("/")[2]') \
|
|
309
|
+
--command "/bin/sh" \
|
|
310
|
+
--interactive
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Where the `CLUSTER_NAME` is the name of the ECS cluster and `TASK_FAMILY_NAME` is the name of the task family that task belongs to.
|
|
314
|
+
|
|
287
315
|
## SSM Connect
|
|
288
316
|
|
|
289
317
|
The [Database](#database) component deploys a database instance inside a private subnet,
|
|
@@ -301,6 +329,11 @@ which enables us to connect to the ec2 instance even though it's inside private
|
|
|
301
329
|
**Prerequisites**
|
|
302
330
|
|
|
303
331
|
1. Install the [Session Manager plugin](https://docs.aws.amazon.com/systems-manager/latest/userguide/install-plugin-macos-overview.html#install-plugin-macos)
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
$ brew install --cask session-manager-plugin
|
|
335
|
+
```
|
|
336
|
+
|
|
304
337
|
2. Generate a new ssh key pair or use the existing one.
|
|
305
338
|
|
|
306
339
|
```bash
|
|
@@ -17,6 +17,18 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
17
17
|
toPort: 22,
|
|
18
18
|
cidrBlocks: ['0.0.0.0/0'],
|
|
19
19
|
},
|
|
20
|
+
{
|
|
21
|
+
protocol: 'tcp',
|
|
22
|
+
fromPort: 80,
|
|
23
|
+
toPort: 80,
|
|
24
|
+
cidrBlocks: ['0.0.0.0/0'],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
protocol: 'tcp',
|
|
28
|
+
fromPort: 443,
|
|
29
|
+
toPort: 443,
|
|
30
|
+
cidrBlocks: ['0.0.0.0/0'],
|
|
31
|
+
},
|
|
20
32
|
],
|
|
21
33
|
egress: [
|
|
22
34
|
{ protocol: '-1', fromPort: 0, toPort: 0, cidrBlocks: ['0.0.0.0/0'] },
|
|
@@ -44,6 +56,21 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
44
56
|
const ssmProfile = new aws.iam.InstanceProfile(`${name}-ssm-profile`, {
|
|
45
57
|
role: role.name,
|
|
46
58
|
}, { parent: this, dependsOn: [ssmPolicyAttachment] });
|
|
59
|
+
this.sshKeyPair = new aws.ec2.KeyPair(`${name}-ec2-keypair`, {
|
|
60
|
+
publicKey: args.sshPublicKey,
|
|
61
|
+
}, { parent: this });
|
|
62
|
+
this.ec2 = new aws.ec2.Instance(`${name}-ec2`, {
|
|
63
|
+
ami: 'ami-067d1e60475437da2',
|
|
64
|
+
associatePublicIpAddress: false,
|
|
65
|
+
instanceType: 't2.micro',
|
|
66
|
+
keyName: this.sshKeyPair.keyName,
|
|
67
|
+
iamInstanceProfile: ssmProfile.name,
|
|
68
|
+
subnetId,
|
|
69
|
+
vpcSecurityGroupIds: [this.ec2SecurityGroup.id],
|
|
70
|
+
tags: {
|
|
71
|
+
Name: `${name}-ec2`,
|
|
72
|
+
},
|
|
73
|
+
}, { parent: this });
|
|
47
74
|
this.ssmVpcEndpoint = new aws.ec2.VpcEndpoint(`${name}-ssm-vpc-endpoint`, {
|
|
48
75
|
vpcId: args.vpc.vpcId,
|
|
49
76
|
ipAddressType: 'ipv4',
|
|
@@ -52,7 +79,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
52
79
|
subnetIds: [subnetId],
|
|
53
80
|
securityGroupIds: [this.ec2SecurityGroup.id],
|
|
54
81
|
privateDnsEnabled: true,
|
|
55
|
-
}, { parent: this });
|
|
82
|
+
}, { parent: this, dependsOn: [this.ec2] });
|
|
56
83
|
this.ec2MessagesVpcEndpoint = new aws.ec2.VpcEndpoint(`${name}-ec2messages-vpc-endpoint`, {
|
|
57
84
|
vpcId: args.vpc.vpcId,
|
|
58
85
|
ipAddressType: 'ipv4',
|
|
@@ -61,7 +88,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
61
88
|
subnetIds: [subnetId],
|
|
62
89
|
securityGroupIds: [this.ec2SecurityGroup.id],
|
|
63
90
|
privateDnsEnabled: true,
|
|
64
|
-
}, { parent: this });
|
|
91
|
+
}, { parent: this, dependsOn: [this.ec2] });
|
|
65
92
|
this.ssmMessagesVpcEndpoint = new aws.ec2.VpcEndpoint(`${name}-ssmmessages-vpc-endpoint`, {
|
|
66
93
|
vpcId: args.vpc.vpcId,
|
|
67
94
|
ipAddressType: 'ipv4',
|
|
@@ -70,22 +97,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
70
97
|
subnetIds: [subnetId],
|
|
71
98
|
securityGroupIds: [this.ec2SecurityGroup.id],
|
|
72
99
|
privateDnsEnabled: true,
|
|
73
|
-
}, { parent: this });
|
|
74
|
-
this.sshKeyPair = new aws.ec2.KeyPair(`${name}-ec2-keypair`, {
|
|
75
|
-
publicKey: args.sshPublicKey,
|
|
76
|
-
}, { parent: this });
|
|
77
|
-
this.ec2 = new aws.ec2.Instance(`${name}-ec2`, {
|
|
78
|
-
ami: 'ami-067d1e60475437da2',
|
|
79
|
-
associatePublicIpAddress: false,
|
|
80
|
-
instanceType: 't2.micro',
|
|
81
|
-
keyName: this.sshKeyPair.keyName,
|
|
82
|
-
iamInstanceProfile: ssmProfile.name,
|
|
83
|
-
subnetId,
|
|
84
|
-
vpcSecurityGroupIds: [this.ec2SecurityGroup.id],
|
|
85
|
-
tags: {
|
|
86
|
-
Name: `${name}-ec2`,
|
|
87
|
-
},
|
|
88
|
-
}, { parent: this });
|
|
100
|
+
}, { parent: this, dependsOn: [this.ec2] });
|
|
89
101
|
this.registerOutputs();
|
|
90
102
|
}
|
|
91
103
|
}
|
|
@@ -197,7 +197,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
197
197
|
.apply(([containerName, image, port, environment, logGroup, region]) => {
|
|
198
198
|
return JSON.stringify([
|
|
199
199
|
{
|
|
200
|
-
readonlyRootFilesystem:
|
|
200
|
+
readonlyRootFilesystem: false,
|
|
201
201
|
name: containerName,
|
|
202
202
|
image,
|
|
203
203
|
essential: true,
|