@studion/infra-code-blocks 0.0.7 → 0.0.8
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
CHANGED
|
@@ -376,11 +376,12 @@ The [Database](#database) component deploys a database instance inside a private
|
|
|
376
376
|
and it's not publicly accessible from outside of VPC.
|
|
377
377
|
<br>
|
|
378
378
|
In order to connect to the database we need to deploy the ec2 instance which will be used
|
|
379
|
-
to
|
|
379
|
+
to forward traffic to the database instance.
|
|
380
380
|
<br>
|
|
381
|
-
Because of security reasons, ec2 instance is also deployed inside private subnet
|
|
381
|
+
Because of security reasons, the ec2 instance is also deployed inside a private subnet
|
|
382
382
|
which means we can't directly connect to it. For that purpose, we use AWS System Manager
|
|
383
|
-
which enables us to connect to the ec2 instance even though it's inside private subnet.
|
|
383
|
+
which enables us to connect to the ec2 instance even though it's inside a private subnet.
|
|
384
|
+
The benefit of using AWS SSM is that we don't need a ssh key pair.
|
|
384
385
|
|
|
385
386
|

|
|
386
387
|
|
|
@@ -392,18 +393,6 @@ which enables us to connect to the ec2 instance even though it's inside private
|
|
|
392
393
|
$ brew install --cask session-manager-plugin
|
|
393
394
|
```
|
|
394
395
|
|
|
395
|
-
2. Generate a new ssh key pair or use the existing one.
|
|
396
|
-
|
|
397
|
-
```bash
|
|
398
|
-
$ ssh-keygen -f my_rsa
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
3. Set stack config property by running:
|
|
402
|
-
|
|
403
|
-
```bash
|
|
404
|
-
$ pulumi config set ssh:publicKey "ssh-rsa Z...9= mymac@Studions-MBP.localdomain"
|
|
405
|
-
```
|
|
406
|
-
|
|
407
396
|
SSM Connect can be enabled by setting `enableSSMConnect` property to `true`.
|
|
408
397
|
|
|
409
398
|
```ts
|
|
@@ -418,20 +407,13 @@ export const ec2InstanceId = project.ec2SSMConnect?.ec2.id;
|
|
|
418
407
|
Open up your terminal and run the following command:
|
|
419
408
|
|
|
420
409
|
```bash
|
|
421
|
-
$ aws ssm start-session --target EC2_INSTANCE_ID --document-name AWS-
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
Where `EC2_INSTANCE_ID` is an ID of the EC2 instance that is created for you. ID can be
|
|
425
|
-
obtained by exporting it from the stack.
|
|
426
|
-
|
|
427
|
-
Next, open another terminal window and run the following command:
|
|
428
|
-
|
|
429
|
-
```bash
|
|
430
|
-
$ ssh ec2-user@localhost -p 9999 -N -L 5555:DATABASE_ADDRESS:DATABASE_PORT -i SSH_PRIVATE_KEY
|
|
410
|
+
$ aws ssm start-session --target EC2_INSTANCE_ID --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters '{"host": ["DATABASE_ADDRESS"], "portNumber":["DATABASE_PORT"], "localPortNumber":["5555"]}'
|
|
431
411
|
```
|
|
432
412
|
|
|
433
|
-
Where `
|
|
434
|
-
|
|
413
|
+
Where `EC2_INSTANCE_ID` is an ID of the EC2 instance that is created for you
|
|
414
|
+
(ID can be obtained by exporting it from the stack), and
|
|
415
|
+
`DATABASE_ADDRESS` and `DATABASE_PORT` are the address and port of the
|
|
416
|
+
database instance.
|
|
435
417
|
|
|
436
418
|
And that is it! 🥳
|
|
437
419
|
Now you can use your favorite database client to connect to the database.
|
|
@@ -439,9 +421,9 @@ Now you can use your favorite database client to connect to the database.
|
|
|
439
421
|

|
|
440
422
|
|
|
441
423
|
It is important that for the host you set `localhost` and for the port you set `5555`
|
|
442
|
-
because we
|
|
443
|
-
DATABASE_ADDRESS:DATABASE_PORT.
|
|
444
|
-
which are set in the `Project`.
|
|
424
|
+
because we are port forwarding traffic from
|
|
425
|
+
localhost:5555 to DATABASE_ADDRESS:DATABASE_PORT.
|
|
426
|
+
For the user, password, and database field, set values which are set in the `Project`.
|
|
445
427
|
|
|
446
428
|
```ts
|
|
447
429
|
const project = new studion.Project('demo-project', {
|
|
@@ -3,7 +3,6 @@ import * as aws from '@pulumi/aws';
|
|
|
3
3
|
import * as awsx from '@pulumi/awsx';
|
|
4
4
|
export type Ec2SSMConnectArgs = {
|
|
5
5
|
vpc: awsx.ec2.Vpc;
|
|
6
|
-
sshPublicKey: pulumi.Input<string>;
|
|
7
6
|
tags?: pulumi.Input<{
|
|
8
7
|
[key: string]: pulumi.Input<string>;
|
|
9
8
|
}>;
|
|
@@ -14,6 +13,5 @@ export declare class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
14
13
|
ec2MessagesVpcEndpoint: aws.ec2.VpcEndpoint;
|
|
15
14
|
ssmMessagesVpcEndpoint: aws.ec2.VpcEndpoint;
|
|
16
15
|
ec2: aws.ec2.Instance;
|
|
17
|
-
sshKeyPair: aws.ec2.KeyPair;
|
|
18
16
|
constructor(name: string, args: Ec2SSMConnectArgs, opts?: pulumi.ComponentResourceOptions);
|
|
19
17
|
}
|
|
@@ -56,14 +56,10 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
56
56
|
const ssmProfile = new aws.iam.InstanceProfile(`${name}-ssm-profile`, {
|
|
57
57
|
role: role.name,
|
|
58
58
|
}, { parent: this, dependsOn: [ssmPolicyAttachment] });
|
|
59
|
-
this.sshKeyPair = new aws.ec2.KeyPair(`${name}-ec2-keypair`, {
|
|
60
|
-
publicKey: args.sshPublicKey,
|
|
61
|
-
}, { parent: this });
|
|
62
59
|
this.ec2 = new aws.ec2.Instance(`${name}-ec2`, {
|
|
63
60
|
ami: 'ami-067d1e60475437da2',
|
|
64
61
|
associatePublicIpAddress: false,
|
|
65
62
|
instanceType: 't2.micro',
|
|
66
|
-
keyName: this.sshKeyPair.keyName,
|
|
67
63
|
iamInstanceProfile: ssmProfile.name,
|
|
68
64
|
subnetId,
|
|
69
65
|
vpcSecurityGroupIds: [this.ec2SecurityGroup.id],
|
|
@@ -39,10 +39,8 @@ class Project extends pulumi.ComponentResource {
|
|
|
39
39
|
this.vpc = this.createVpc();
|
|
40
40
|
this.createServices(services);
|
|
41
41
|
if (args.enableSSMConnect) {
|
|
42
|
-
const sshConfig = new pulumi.Config('ssh');
|
|
43
42
|
this.ec2SSMConnect = new ec2_ssm_connect_1.Ec2SSMConnect(`${name}-ssm-connect`, {
|
|
44
43
|
vpc: this.vpc,
|
|
45
|
-
sshPublicKey: sshConfig.require('publicKey'),
|
|
46
44
|
});
|
|
47
45
|
}
|
|
48
46
|
this.registerOutputs();
|