Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 042d589

Browse files
lmouhibvgkowski
andauthored
doc: Add example for emr on eks (#501)
* Add example for emr on eks * remove test file Co-authored-by: Vincent Gromakowski <[email protected]>
1 parent 0a20f59 commit 042d589

File tree

6 files changed

+167
-0
lines changed

6 files changed

+167
-0
lines changed

examples/emr-eks-app/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Welcome to your CDK TypeScript project
2+
3+
This is a blank project for CDK development with TypeScript.
4+
5+
The `cdk.json` file tells the CDK Toolkit how to execute your app.
6+
7+
## Useful commands
8+
9+
* `npm run build` compile typescript to js
10+
* `npm run watch` watch for changes and compile
11+
* `npm run test` perform the jest unit tests
12+
* `cdk deploy` deploy this stack to your default AWS account/region
13+
* `cdk diff` compare deployed stack with current state
14+
* `cdk synth` emits the synthesized CloudFormation template
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
import 'source-map-support/register';
3+
import * as cdk from 'aws-cdk-lib';
4+
import { EmrEksAppStack } from '../lib/emr-eks-app-stack';
5+
6+
const app = new cdk.App();
7+
new EmrEksAppStack(app, 'EmrEksAppStack', {
8+
/* If you don't specify 'env', this stack will be environment-agnostic.
9+
* Account/Region-dependent features and context lookups will not work,
10+
* but a single synthesized template can be deployed anywhere. */
11+
12+
/* Uncomment the next line to specialize this stack for the AWS Account
13+
* and Region that are implied by the current CLI configuration. */
14+
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
15+
16+
/* Uncomment the next line if you know exactly what Account and Region you
17+
* want to deploy the stack to. */
18+
// env: { account: '123456789012', region: 'us-east-1' },
19+
20+
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
21+
});

examples/emr-eks-app/jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/test'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
}
8+
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import * as ara from 'aws-analytics-reference-architecture';
4+
import * as iam from 'aws-cdk-lib/aws-iam' ;
5+
6+
7+
export class EmrEksAppStack extends cdk.Stack {
8+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
9+
super(scope, id, props);
10+
11+
const emrEks = ara.EmrEksCluster.getOrCreate(this,{
12+
eksAdminRoleArn:'',
13+
eksClusterName:''
14+
});
15+
16+
const virtualCluster = emrEks.addEmrVirtualCluster(this,{
17+
name:'my-emr-eks-cluster',
18+
eksNamespace: 'batchjob',
19+
createNamespace: true,
20+
});
21+
22+
const emrEksPolicy = new iam.ManagedPolicy(this,'managed-policy',{
23+
statements: [
24+
new iam.PolicyStatement({
25+
effect: iam.Effect.ALLOW,
26+
actions:['s3:PutObject','s3:GetObject','s3:ListBucket'],
27+
resources:['*'],
28+
}),
29+
new iam.PolicyStatement({
30+
effect: iam.Effect.ALLOW, actions:['logs:PutLogEvents','logs:CreateLogStream','logs:DescribeLogGroups','logs:DescribeLogStreams'],
31+
resources:['arn:aws:logs:*:*:*'],
32+
}),
33+
]
34+
});
35+
36+
37+
const role = emrEks.createExecutionRole(this,'emr-eks-execution-role',emrEksPolicy, 'batchjob','execRoleJob');
38+
39+
// Virtual cluster Id to reference in jobs
40+
new cdk.CfnOutput(this, 'VirtualClusterId', { value: virtualCluster.attrId });
41+
// Job config for each nodegroup
42+
new cdk.CfnOutput(this, 'CriticalConfig', { value: emrEks.criticalDefaultConfig });
43+
// Execution role arn
44+
new cdk.CfnOutput(this, 'ExecRoleArn', { value: role.roleArn });
45+
46+
47+
const notebookPlatform = new ara.NotebookPlatform(this, 'platform-notebook', {
48+
emrEks: emrEks,
49+
eksNamespace: 'dataanalysis',
50+
studioName: 'platform',
51+
studioAuthMode: ara.StudioAuthMode.IAM,
52+
});
53+
54+
notebookPlatform.addUser([{
55+
identityName:'',
56+
notebookManagedEndpoints: [{
57+
emrOnEksVersion: 'emr-6.8.0-latest',
58+
executionPolicy: emrEksPolicy,
59+
managedEndpointName: 'myendpoint'
60+
}],
61+
}]);
62+
63+
64+
}
65+
}

examples/emr-eks-app/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "emr-eks-app",
3+
"version": "0.1.0",
4+
"bin": {
5+
"emr-eks-app": "bin/emr-eks-app.js"
6+
},
7+
"scripts": {
8+
"build": "tsc",
9+
"watch": "tsc -w",
10+
"test": "jest",
11+
"cdk": "cdk"
12+
},
13+
"devDependencies": {
14+
"@types/jest": "^27.5.2",
15+
"@types/node": "10.17.27",
16+
"@types/prettier": "2.6.0",
17+
"jest": "^27.5.1",
18+
"ts-jest": "^27.1.4",
19+
"aws-cdk": "2.46.0",
20+
"ts-node": "^10.9.1",
21+
"typescript": "~3.9.7"
22+
},
23+
"dependencies": {
24+
"aws-analytics-reference-architecture": "^2.4.9",
25+
"aws-cdk-lib": "2.46.0",
26+
"constructs": "^10.0.0",
27+
"source-map-support": "^0.5.21"
28+
}
29+
}

examples/emr-eks-app/tsconfig.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2018",
4+
"module": "commonjs",
5+
"lib": [
6+
"es2018"
7+
],
8+
"declaration": true,
9+
"strict": true,
10+
"noImplicitAny": true,
11+
"strictNullChecks": true,
12+
"noImplicitThis": true,
13+
"alwaysStrict": true,
14+
"noUnusedLocals": false,
15+
"noUnusedParameters": false,
16+
"noImplicitReturns": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"inlineSourceMap": true,
19+
"inlineSources": true,
20+
"experimentalDecorators": true,
21+
"strictPropertyInitialization": false,
22+
"typeRoots": [
23+
"./node_modules/@types"
24+
]
25+
},
26+
"exclude": [
27+
"node_modules",
28+
"cdk.out"
29+
]
30+
}

0 commit comments

Comments
 (0)