Skip to content

Commit 008f044

Browse files
authored
Merge pull request #291 from aws-samples/staging
Update main
2 parents f4652d6 + 38b75ba commit 008f044

File tree

9 files changed

+625
-1040
lines changed

9 files changed

+625
-1040
lines changed

PetAdoptions/cdk/pet_stack/buildspec.yml

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

PetAdoptions/cdk/pet_stack/lib/services.ts

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ export class Services extends Stack {
4141
constructor(scope: Construct, id: string, props?: StackProps) {
4242
super(scope, id, props);
4343

44-
var isEventEngine = 'false';
45-
if (this.node.tryGetContext('is_event_engine') != undefined)
46-
{
47-
isEventEngine = this.node.tryGetContext('is_event_engine');
48-
}
49-
5044
const stackName = id;
5145

5246
// Create SQS resource to send Pet adoption messages to
@@ -342,7 +336,8 @@ export class Services extends Stack {
342336
defaultCapacityInstance: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MEDIUM),
343337
secretsEncryptionKey: secretsKey,
344338
version: KubernetesVersion.of('1.28'),
345-
kubectlLayer: new KubectlLayer(this, 'kubectl')
339+
kubectlLayer: new KubectlLayer(this, 'kubectl'),
340+
authenticationMode: eks.AuthenticationMode.API_AND_CONFIG_MAP,
346341
});
347342

348343
const clusterSG = ec2.SecurityGroup.fromSecurityGroupId(this,'ClusterSG',cluster.clusterSecurityGroupId);
@@ -445,60 +440,16 @@ export class Services extends Stack {
445440

446441
loadBalancerserviceaccount.assumeRolePolicy?.addStatements(loadBalancer_trustRelationship);
447442

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-
}
457-
458-
if (isEventEngine === 'true')
459-
{
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-
479-
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-
488-
}
489-
490443
const eksAdminArn = this.node.tryGetContext('admin_role');
491444
if ((eksAdminArn!=undefined)&&(eksAdminArn.length > 0)) {
492-
const role = iam.Role.fromRoleArn(this,"ekdAdminRoleArn",eksAdminArn,{mutable:false});
493-
cluster.awsAuth.addMastersRole(role)
445+
const adminRole = iam.Role.fromRoleArn(this,"ekdAdminRoleArn",eksAdminArn,{mutable:false});
446+
cluster.grantAccess('TeamRoleAccess', adminRole.roleArn, [
447+
eks.AccessPolicy.fromAccessPolicyName('AmazonEKSClusterAdminPolicy', {
448+
accessScopeType: eks.AccessScopeType.CLUSTER
449+
})
450+
]);
494451
}
495452

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

504455
xRayYaml[0].metadata.annotations["eks.amazonaws.com/role-arn"] = new CfnJson(this, "xray_Role", { value : `${xrayserviceaccount.roleArn}` });
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
echo ---------------------------------------------------------------------------------------------
4-
echo This script destroys the CDK stack
4+
echo This script destroys the resources created in the workshop
55
echo ---------------------------------------------------------------------------------------------
66

77
if [ -z "$AWS_REGION" ]; then
@@ -11,7 +11,7 @@ fi
1111

1212
# Disable Contributor Insights
1313
DDB_CONTRIB=$(aws ssm get-parameter --name '/petstore/dynamodbtablename' | jq .Parameter.Value -r)
14-
aws dynamodb update-contributor-insights --table-name $DDB_CONTRIB --contributor-insights-action DISABLE
14+
aws dynamodb update-contributor-insights --table-name $DDB_CONTRIB --contributor-insights-action DISABLE
1515

1616
echo STARTING SERVICES CLEANUP
1717
echo -----------------------------
@@ -22,25 +22,28 @@ STACK_NAME_APP=$(aws ssm get-parameter --name '/eks/petsite/stackname' --region
2222

2323
# Set default name in case Parameters are gone (partial deletion)
2424
if [ -z $STACK_NAME ]; then STACK_NAME="Services"; fi
25-
if [ -z $STACK_NAME_APP ]; then STACK_NAME_APP="Applications"; fi
25+
if [ -z $STACK_NAME_APP ]; then STACK_NAME_APP="Applications"; fi
26+
if [ -z $STACK_NAME_CODEPIPELINE ]; then STACK_NAME_CODEPIPELINE="Observability-Workshop"; fi
2627

2728
# Fix for CDK teardown issues
2829
aws eks update-kubeconfig --name PetSite
2930
kubectl delete -f https://raw.githubusercontent.com/aws-samples/one-observability-demo/main/PetAdoptions/cdk/pet_stack/resources/load_balancer/crds.yaml
3031

31-
#Deleting keycloak
32+
#Deleting keycloak
3233
kubectl delete namespace keycloak --force
3334

34-
# Get rid of all resources (Application first, then cluster or it will fail)
35-
cdk destroy $STACK_NAME_APP --force
36-
cdk destroy $STACK_NAME --force
37-
3835
# Sometimes the SqlSeeder doesn't get deleted cleanly. This helps clean up the environment completely including Sqlseeder
3936
aws cloudformation delete-stack --stack-name $STACK_NAME_APP
37+
aws cloudformation wait stack-delete-complete --stack-name $STACK_NAME_APP
4038
aws cloudformation delete-stack --stack-name $STACK_NAME
39+
aws cloudformation wait stack-delete-complete --stack-name $STACK_NAME
4140

4241
aws cloudwatch delete-dashboards --dashboard-names "EKS_FluentBit_Dashboard"
4342

43+
# delete the code pipeline stack
44+
aws cloudformation delete-stack --stack-name $STACK_NAME_CODEPIPELINE
45+
aws cloudformation wait stack-delete-complete --stack-name $STACK_NAME_CODEPIPELINE
46+
4447
echo CDK BOOTSTRAP WAS NOT DELETED
4548

4649
echo ----- ✅ DONE --------

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 iam get-role --role-name $(aws sts get-caller-identity --query Arn --output text | awk -F/ '{print $(NF-1)}') --query Role.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.

buildspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ phases:
1616
- npm install
1717
- if [ -z "$CDK_STACK" ] ; then cdk bootstrap ; else echo "Already bootstrapped" ; fi
1818
- npm run build
19-
- cdk deploy Services --context admin_role=${EE_TEAM_ROLE_ARN} --context is_event_engine="true" --require-approval=never --verbose -O ./out/out.json
19+
- cdk deploy Services --context admin_role=${EE_TEAM_ROLE_ARN} --require-approval=never --verbose -O ./out/out.json
2020
- cdk deploy Applications --require-approval=never --verbose -O ./out/out.json
2121
artifacts:
2222
files: "./PetAdoptions/cdk/pet_stack/out/out.json"

0 commit comments

Comments
 (0)