Skip to content

Commit 1ea645d

Browse files
committed
Cloud9 to CloudShell migration
1 parent eb29542 commit 1ea645d

File tree

5 files changed

+569
-999
lines changed

5 files changed

+569
-999
lines changed

PetAdoptions/cdk/pet_stack/lib/services.ts

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ export class Services extends Stack {
342342
defaultCapacityInstance: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MEDIUM),
343343
secretsEncryptionKey: secretsKey,
344344
version: KubernetesVersion.of('1.28'),
345-
kubectlLayer: new KubectlLayer(this, 'kubectl')
345+
kubectlLayer: new KubectlLayer(this, 'kubectl'),
346+
authenticationMode: eks.AuthenticationMode.API_AND_CONFIG_MAP,
346347
});
347348

348349
const clusterSG = ec2.SecurityGroup.fromSecurityGroupId(this,'ClusterSG',cluster.clusterSecurityGroupId);
@@ -445,60 +446,27 @@ export class Services extends Stack {
445446

446447
loadBalancerserviceaccount.assumeRolePolicy?.addStatements(loadBalancer_trustRelationship);
447448

448-
// Fix for EKS Dashboard access
449-
450-
const dashboardRoleYaml = yaml.loadAll(readFileSync("./resources/dashboard.yaml","utf8")) as Record<string,any>[];
451-
452-
const dashboardRoleArn = this.node.tryGetContext('dashboard_role_arn');
453-
if((dashboardRoleArn != undefined)&&(dashboardRoleArn.length > 0)) {
454-
const role = iam.Role.fromRoleArn(this, "DashboardRoleArn",dashboardRoleArn,{mutable:false});
455-
cluster.awsAuth.addRoleMapping(role,{groups:["dashboard-view"]});
456-
}
457449

458450
if (isEventEngine === 'true')
459451
{
460-
461-
var c9Env = new Cloud9Environment(this, 'Cloud9Environment', {
462-
vpcId: theVPC.vpcId,
463-
subnetId: theVPC.publicSubnets[0].subnetId,
464-
cloud9OwnerArn: "assumed-role/WSParticipantRole/Participant",
465-
templateFile: __dirname + "/../../../../cloud9-cfn.yaml"
466-
467-
});
468-
469-
var c9role = c9Env.c9Role;
470-
471-
// Dynamically check if AWSCloud9SSMAccessRole and AWSCloud9SSMInstanceProfile exists
472-
const c9SSMRole = new iam.Role(this,'AWSCloud9SSMAccessRole', {
473-
path: '/service-role/',
474-
roleName: 'AWSCloud9SSMAccessRole',
475-
assumedBy: new iam.CompositePrincipal(new iam.ServicePrincipal("ec2.amazonaws.com"), new iam.ServicePrincipal("cloud9.amazonaws.com")),
476-
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName("AWSCloud9SSMInstanceProfile"),iam.ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess")]
477-
});
478-
479452
const teamRole = iam.Role.fromRoleArn(this,'TeamRole',"arn:aws:iam::" + stack.account +":role/WSParticipantRole");
480-
cluster.awsAuth.addRoleMapping(teamRole,{groups:["dashboard-view"]});
481-
482-
483-
if (c9role!=undefined) {
484-
cluster.awsAuth.addMastersRole(iam.Role.fromRoleArn(this, 'c9role', c9role.attrArn, { mutable: false }));
485-
}
486-
487-
453+
cluster.grantAccess('TeamRoleAccess', teamRole.roleArn, [
454+
eks.AccessPolicy.fromAccessPolicyName('AmazonEKSClusterAdminPolicy', {
455+
accessScopeType: eks.AccessScopeType.CLUSTER
456+
})
457+
]);
488458
}
489459

490460
const eksAdminArn = this.node.tryGetContext('admin_role');
491461
if ((eksAdminArn!=undefined)&&(eksAdminArn.length > 0)) {
492-
const role = iam.Role.fromRoleArn(this,"ekdAdminRoleArn",eksAdminArn,{mutable:false});
493-
cluster.awsAuth.addMastersRole(role)
462+
const adminRole = iam.Role.fromRoleArn(this,"ekdAdminRoleArn",eksAdminArn,{mutable:false});
463+
cluster.grantAccess('TeamRoleAccess', adminRole.roleArn, [
464+
eks.AccessPolicy.fromAccessPolicyName('AmazonEKSClusterAdminPolicy', {
465+
accessScopeType: eks.AccessScopeType.CLUSTER
466+
})
467+
]);
494468
}
495469

496-
const dahshboardManifest = new eks.KubernetesManifest(this,"k8sdashboardrbac",{
497-
cluster: cluster,
498-
manifest: dashboardRoleYaml
499-
});
500-
501-
502470
var xRayYaml = yaml.loadAll(readFileSync("./resources/k8s_petsite/xray-daemon-config.yaml","utf8")) as Record<string,any>[];
503471

504472
xRayYaml[0].metadata.annotations["eks.amazonaws.com/role-arn"] = new CfnJson(this, "xray_Role", { value : `${xrayserviceaccount.roleArn}` });

PetAdoptions/cdk/pet_stack/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
3-
"target":"ES2018",
3+
"target":"ES2021",
44
"module": "commonjs",
5-
"lib": ["es2018"],
5+
"lib": ["es2021"],
66
"declaration": true,
77
"strict": true,
88
"noImplicitAny": true,

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ This repo contains a sample application which is used in the One Observability D
66

77
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
88

9+
## Instructions
10+
11+
To deploy this workshop on your own account you need to have an IAM role with elevated priviliges and the `aws-cli` installed. Then, from the root
12+
of the repository run the following command:
13+
14+
```
15+
aws cloudformation create-stack --stack-name Observability-Workshop --template-body file://codepipeline-stack.yaml --capabilities CAPABILITY_NAMED_IAM --parameters ParameterKey=UserRoleArn,ParameterValue=$(aws sts get-caller-identity --query Arn --output text)
16+
```
17+
18+
You can replace the role specified in the paramter `UserRoleArn` with any other role with access to AWS CloudShell if you need so.
19+
920
## License
1021

1122
This library is licensed under the MIT-0 License. See the LICENSE file.

0 commit comments

Comments
 (0)