|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: MIT-0 |
| 3 | + |
| 4 | +/** |
| 5 | + * Tests EmrEksCluster |
| 6 | + * |
| 7 | + * @group integ/notebook-platform |
| 8 | + */ |
| 9 | + |
| 10 | +import { ManagedPolicy, PolicyStatement } from '@aws-cdk/aws-iam'; |
| 11 | +import * as cdk from '@aws-cdk/core'; |
| 12 | +import { ArnFormat, Aws } from '@aws-cdk/core'; |
| 13 | +import { SdkProvider } from 'aws-cdk/lib/api/aws-auth'; |
| 14 | +import { CloudFormationDeployments } from 'aws-cdk/lib/api/cloudformation-deployments'; |
| 15 | + |
| 16 | +import { NotebookPlatform, StudioAuthMode } from '../../src'; |
| 17 | +import { EmrEksCluster } from '../../src/emr-eks-platform'; |
| 18 | + |
| 19 | +jest.setTimeout(2000000); |
| 20 | +// GIVEN |
| 21 | +const integTestApp = new cdk.App(); |
| 22 | +const stack = new cdk.Stack(integTestApp, 'notebookPlatformE2eTest'); |
| 23 | + |
| 24 | +const emrEksCluster = EmrEksCluster.getOrCreate(stack, { |
| 25 | + eksAdminRoleArn: 'arn:aws:iam::123445678912:role/gromav', |
| 26 | +}); |
| 27 | + |
| 28 | +const notebookPlatform = new NotebookPlatform(stack, 'platform-notebook', { |
| 29 | + emrEks: emrEksCluster, |
| 30 | + eksNamespace: 'notebookspace', |
| 31 | + studioName: 'testNotebook', |
| 32 | + studioAuthMode: StudioAuthMode.IAM, |
| 33 | +}); |
| 34 | + |
| 35 | + |
| 36 | +const policy1 = new ManagedPolicy(stack, 'MyPolicy1', { |
| 37 | + statements: [ |
| 38 | + new PolicyStatement({ |
| 39 | + resources: ['*'], |
| 40 | + actions: ['s3:*'], |
| 41 | + }), |
| 42 | + new PolicyStatement({ |
| 43 | + resources: [ |
| 44 | + stack.formatArn({ |
| 45 | + account: Aws.ACCOUNT_ID, |
| 46 | + region: Aws.REGION, |
| 47 | + service: 'logs', |
| 48 | + resource: '*', |
| 49 | + arnFormat: ArnFormat.NO_RESOURCE_NAME, |
| 50 | + }), |
| 51 | + ], |
| 52 | + actions: [ |
| 53 | + 'logs:*', |
| 54 | + ], |
| 55 | + }), |
| 56 | + ], |
| 57 | +}); |
| 58 | + |
| 59 | +notebookPlatform.addUser([{ |
| 60 | + identityName: 'janeDoe', |
| 61 | + notebookManagedEndpoints: [ |
| 62 | + { |
| 63 | + emrOnEksVersion: 'emr-6.4.0-latest', |
| 64 | + executionPolicy: policy1, |
| 65 | + }, |
| 66 | + ], |
| 67 | +}]); |
| 68 | + |
| 69 | +new cdk.CfnOutput(stack, 'EmrEksAdminRoleOutput', { |
| 70 | + value: emrEksCluster.eksCluster.adminRole.roleArn, |
| 71 | + exportName: 'emrEksAdminRole', |
| 72 | +}); |
| 73 | + |
| 74 | +describe('deploy succeed', () => { |
| 75 | + it('can be deploy succcessfully', async () => { |
| 76 | + // GIVEN |
| 77 | + const stackArtifact = integTestApp.synth().getStackByName(stack.stackName); |
| 78 | + |
| 79 | + const sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({ |
| 80 | + profile: process.env.AWS_PROFILE, |
| 81 | + }); |
| 82 | + const cloudFormation = new CloudFormationDeployments({ sdkProvider }); |
| 83 | + |
| 84 | + // WHEN |
| 85 | + const deployResult = await cloudFormation.deployStack({ |
| 86 | + stack: stackArtifact, |
| 87 | + }); |
| 88 | + |
| 89 | + // THEN |
| 90 | + expect(deployResult.outputs.emrEksAdminRole).toEqual('arn:aws:iam::123445678912:role/gromav'); |
| 91 | + |
| 92 | + }, 9000000); |
| 93 | +}); |
| 94 | + |
| 95 | +afterAll(async () => { |
| 96 | + const stackArtifact = integTestApp.synth().getStackByName(stack.stackName); |
| 97 | + |
| 98 | + const sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({ |
| 99 | + profile: process.env.AWS_PROFILE, |
| 100 | + }); |
| 101 | + const cloudFormation = new CloudFormationDeployments({ sdkProvider }); |
| 102 | + |
| 103 | + await cloudFormation.destroyStack({ |
| 104 | + stack: stackArtifact, |
| 105 | + }); |
| 106 | +}); |
0 commit comments