Skip to content

Commit 61f731c

Browse files
authored
Merge pull request #246 from aws-samples/staging
Merging changes from Staging to main
2 parents b252679 + 15fe722 commit 61f731c

File tree

14 files changed

+1299
-602
lines changed

14 files changed

+1299
-602
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Construct } from "constructs";
2+
import * as cloudformation_include from "aws-cdk-lib/cloudformation-include";
3+
import { CfnRole } from "aws-cdk-lib/aws-iam";
4+
5+
export interface Cloud9EnvironmentProps {
6+
name?: string;
7+
vpcId: string;
8+
subnetId: string;
9+
templateFile: string;
10+
cloud9OwnerArn?: string;
11+
}
12+
13+
export class Cloud9Environment extends Construct {
14+
public readonly c9Role: CfnRole;
15+
constructor(scope: Construct, id: string, props: Cloud9EnvironmentProps) {
16+
super(scope, id);
17+
18+
const template = new cloudformation_include.CfnInclude(this, 'Cloud9Template', {
19+
templateFile: props.templateFile,
20+
parameters: {
21+
'CreateVPC': false,
22+
'Cloud9VPC': props.vpcId,
23+
'Cloud9Subnet': props.subnetId
24+
},
25+
preserveLogicalIds: false
26+
});
27+
28+
if (props.name) {
29+
template.getParameter("EnvironmentName").default = props.name;
30+
}
31+
32+
if (props.cloud9OwnerArn) {
33+
template.getParameter("Cloud9OwnerRole").default = props.cloud9OwnerArn.valueOf();
34+
}
35+
36+
this.c9Role = template.getResource("C9Role") as CfnRole;
37+
38+
}
39+
}

PetAdoptions/cdk/pet_stack/lib/services.ts

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as s3 from 'aws-cdk-lib/aws-s3'
99
import * as s3seeder from 'aws-cdk-lib/aws-s3-deployment'
1010
import * as rds from 'aws-cdk-lib/aws-rds';
1111
import * as ssm from 'aws-cdk-lib/aws-ssm';
12+
import * as kms from 'aws-cdk-lib/aws-kms';
1213
import * as eks from 'aws-cdk-lib/aws-eks';
1314
import * as yaml from 'js-yaml';
1415
import * as path from 'path';
@@ -31,6 +32,8 @@ import { CfnJson, RemovalPolicy, Fn, Duration, Stack, StackProps, CfnOutput } fr
3132
import { readFileSync } from 'fs';
3233
import 'ts-replace-all'
3334
import { TreatMissingData, ComparisonOperator } from 'aws-cdk-lib/aws-cloudwatch';
35+
import { KubectlLayer } from 'aws-cdk-lib/lambda-layer-kubectl';
36+
import { Cloud9Environment } from './modules/core/cloud9';
3437

3538
export class Services extends Stack {
3639
constructor(scope: Construct, id: string, props?: StackProps) {
@@ -109,7 +112,8 @@ export class Services extends Stack {
109112
}
110113
// The VPC where all the microservices will be deployed into
111114
const theVPC = new ec2.Vpc(this, 'Microservices', {
112-
cidr: cidrRange,
115+
ipAddresses: ec2.IpAddresses.cidr(cidrRange),
116+
// cidr: cidrRange,
113117
natGateways: 1,
114118
maxAzs: 2
115119
});
@@ -327,13 +331,16 @@ export class Services extends Stack {
327331
parameterName: '/eks/petsite/EKSMasterRoleArn'
328332
})
329333

334+
const secretsKey = new kms.Key(this, 'SecretsKey');
330335
const cluster = new eks.Cluster(this, 'petsite', {
331336
clusterName: 'PetSite',
332337
mastersRole: clusterAdmin,
333338
vpc: theVPC,
334339
defaultCapacity: 2,
335340
defaultCapacityInstance: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MEDIUM),
336-
version: KubernetesVersion.V1_23
341+
secretsEncryptionKey: secretsKey,
342+
version: KubernetesVersion.of('1.27'),
343+
kubectlLayer: new KubectlLayer(this, 'kubectl')
337344
});
338345

339346
const clusterSG = ec2.SecurityGroup.fromSecurityGroupId(this,'ClusterSG',cluster.clusterSecurityGroupId);
@@ -448,9 +455,16 @@ export class Services extends Stack {
448455

449456
if (isEventEngine === 'true')
450457
{
451-
var c9role = undefined
452-
var c9InstanceProfile = undefined
453-
var c9env = undefined
458+
459+
var c9Env = new Cloud9Environment(this, 'Cloud9Environment', {
460+
vpcId: theVPC.vpcId,
461+
subnetId: theVPC.publicSubnets[0].subnetId,
462+
cloud9OwnerArn: "assumed-role/WSParticipantRole/Participant",
463+
templateFile: __dirname + "/../../../../cloud9-cfn.yaml"
464+
465+
});
466+
467+
var c9role = c9Env.c9Role;
454468

455469
// Dynamically check if AWSCloud9SSMAccessRole and AWSCloud9SSMInstanceProfile exists
456470
const c9SSMRole = new iam.Role(this,'AWSCloud9SSMAccessRole', {
@@ -460,51 +474,15 @@ export class Services extends Stack {
460474
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName("AWSCloud9SSMInstanceProfile"),iam.ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess")]
461475
});
462476

463-
const c9SSMRoleNoPath = iam.Role.fromRoleArn(this,'c9SSMRoleNoPath', "arn:aws:iam::" + stack.account + ":role/AWSCloud9SSMAccessRole")
464-
cluster.awsAuth.addMastersRole(c9SSMRoleNoPath);
465-
466-
new iam.CfnInstanceProfile(this, 'AWSCloud9SSMInstanceProfile', {
467-
path: '/cloud9/',
468-
roles: [c9SSMRole.roleName],
469-
instanceProfileName: 'AWSCloud9SSMInstanceProfile'
470-
});
471-
472-
c9env = new cloud9.CfnEnvironmentEC2(this,"CloudEnv",{
473-
ownerArn: "arn:aws:iam::" + stack.account +":assumed-role/WSParticipantRole/Participant",
474-
instanceType: "t2.micro",
475-
name: "observabilityworkshop",
476-
subnetId: theVPC.privateSubnets[0].subnetId,
477-
connectionType: 'CONNECT_SSM',
478-
repositories: [
479-
{
480-
repositoryUrl: "https://github.com/aws-samples/one-observability-demo.git",
481-
pathComponent: "workshopfiles/one-observability-demo"
482-
}
483-
]
484-
});
485-
486-
c9role = new iam.Role(this,'cloud9InstanceRole', {
487-
assumedBy: new iam.ServicePrincipal("ec2.amazonaws.com"),
488-
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess"), iam.ManagedPolicy.fromAwsManagedPolicyName("AmazonSSMManagedInstanceCore")],
489-
roleName: "observabilityworkshop-admin"
490-
});
491-
492-
c9InstanceProfile = new iam.CfnInstanceProfile(this,'cloud9InstanceProfile', {
493-
roles: [c9role.roleName],
494-
instanceProfileName: "observabilityworkshop-profile"
495-
})
496-
497-
const teamRole = iam.Role.fromRoleArn(this,'TeamRole',"arn:aws:iam::" + stack.account +":role/TeamRole");
477+
const teamRole = iam.Role.fromRoleArn(this,'TeamRole',"arn:aws:iam::" + stack.account +":role/WSParticipantRole");
498478
cluster.awsAuth.addRoleMapping(teamRole,{groups:["dashboard-view"]});
479+
499480

481+
if (c9role!=undefined) {
482+
cluster.awsAuth.addMastersRole(iam.Role.fromRoleArn(this, 'c9role', c9role.attrArn, { mutable: false }));
483+
}
500484

501485

502-
if (c9role!=undefined)
503-
cluster.awsAuth.addMastersRole(c9role)
504-
505-
if (c9env!=undefined)
506-
cluster.node.addDependency(c9env)
507-
508486
}
509487

510488
const eksAdminArn = this.node.tryGetContext('admin_role');

PetAdoptions/cdk/pet_stack/lib/services/stepfn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class PetAdoptionsStepFn extends Construct {
5959

6060

6161
this.stepFn = new sfn.StateMachine(this, 'StateMachine', {
62-
definition,
62+
definitionBody: sfn.DefinitionBody.fromChainable(definition),
6363
tracingEnabled: true,
6464
timeout: Duration.minutes(5)
6565
});

PetAdoptions/cdk/pet_stack/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
},
1414
"devDependencies": {
1515
"@aws-cdk/assert": "2.68.0",
16-
"@types/jest": "^29.5.2",
17-
"@types/node": "^20.2.5",
18-
"aws-cdk": "2.82.0",
19-
"constructs": "^10.2.43",
20-
"ts-jest": "^29.1.0",
16+
"@types/jest": "^29.5.4",
17+
"@types/node": "^20.5.7",
18+
"aws-cdk": "2.93.0",
19+
"constructs": "^10.2.69",
20+
"ts-jest": "^29.1.1",
2121
"ts-node": "^10.9.1",
2222
"ts-replace-all": "1.0.0",
23-
"typescript": "^5.1.3",
24-
"cdk-nag": "^2.27.28"
23+
"typescript": "^5.2.2",
24+
"cdk-nag": "^2.27.114"
2525
},
2626
"dependencies": {
27-
"@aws-cdk/aws-lambda-python-alpha": "^2.82.0-alpha.0",
27+
"@aws-cdk/aws-lambda-python-alpha": "^2.93.0-alpha.0",
2828
"@types/js-yaml": "4.0.5",
29-
"aws-cdk-lib": "^2.82.0",
30-
"cdk-ecr-deployment": "^2.5.6",
31-
"jest": "^29.5.0",
29+
"aws-cdk-lib": "^2.93.0",
30+
"cdk-ecr-deployment": "^2.5.30",
31+
"jest": "^29.6.4",
3232
"js-yaml": "^4.1.0",
3333
"source-map-support": "^0.5.21"
3434
}

PetAdoptions/cdk/pet_stack/resources/destroy_stack.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ if [ -z $STACK_NAME_APP ]; then STACK_NAME_APP="Applications"; fi
2828
aws eks update-kubeconfig --name PetSite
2929
kubectl delete -f https://raw.githubusercontent.com/aws-samples/one-observability-demo/main/PetAdoptions/cdk/pet_stack/resources/load_balancer/crds.yaml
3030

31+
#Deleting keycloak
32+
kubectl delete namespace keycloak --force
33+
3134
# Get rid of all resources (Application first, then cluster or it will fail)
3235
cdk destroy $STACK_NAME_APP --force
3336
cdk destroy $STACK_NAME --force

PetAdoptions/cdk/pet_stack/resources/setup-ssm-agent.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,6 @@ subjects:
3434
name: ssm-agent-installer
3535
namespace: node-configuration-daemonset
3636
---
37-
apiVersion: policy/v1beta1
38-
kind: PodSecurityPolicy
39-
metadata:
40-
name: ssm-agent-installer
41-
spec:
42-
privileged: true
43-
hostPID: true
44-
seLinux:
45-
rule: RunAsAny
46-
supplementalGroups:
47-
rule: RunAsAny
48-
runAsUser:
49-
rule: RunAsAny
50-
fsGroup:
51-
rule: RunAsAny
52-
---
5337
apiVersion: v1
5438
kind: ConfigMap
5539
metadata:

PetAdoptions/envsetup.sh

Lines changed: 0 additions & 75 deletions
This file was deleted.

PetAdoptions/envsetup_ee.sh

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)