Skip to content

Commit

Permalink
fixing trust policy and network configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
malachi-constant committed Jul 6, 2023
1 parent 3b85853 commit 163ed3a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
4 changes: 2 additions & 2 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/core/emr-serverless-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class EMRServerlessCluster extends Construct {
this.vpc = ec2.Vpc.fromLookup(scope, "VPC", { vpcId: props.vpcId });
} else if (props.vpcCidr) {
this.vpc = this.createVpc(scope, name, props.vpcCidr);
} else {
throw new Error("One of 'vpcId' or 'vpcCidr' must be provided");
}

if (this.vpc) {
Expand All @@ -67,7 +69,7 @@ export class EMRServerlessCluster extends Construct {
}

const emrServerlessRole = new iam.Role(scope, "EMR Serverless Cluster Role", {
assumedBy: new iam.ServicePrincipal("emr-serveless.amazonaws.com"),
assumedBy: new iam.ServicePrincipal("emr-serverless.amazonaws.com"),
path: "/service-role/",
});
emrServerlessRole.addManagedPolicy(
Expand Down Expand Up @@ -128,8 +130,7 @@ export class EMRServerlessCluster extends Construct {
...mergedProps,
});
}
createVpc(scope: Construct, environmentName: string, vpcCidr: string): ec2.IVpc {
const resourceName = `${environmentName}-MWAA`;
createVpc(scope: Construct, resourceName: string, vpcCidr: string): ec2.IVpc {
const vpcCIDRMask = +vpcCidr.split("/")[1];
if (vpcCIDRMask > 20 || vpcCIDRMask < 16) {
throw new Error("Vpc Cidr Range must of size >=16 and <=20");
Expand Down
49 changes: 32 additions & 17 deletions test/emr-serverless-cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@ import * as s3 from "aws-cdk-lib/aws-s3";

import { EMRServerlessCluster } from "../src";

test("EMR Serverless Cluster Basic", () => {
const stack = new cdk.Stack();

new EMRServerlessCluster(stack, "EMR Serverless Cluster", {
releaseLabel: "emr-6.11.0",
type: "SPARK",
});
const template = Template.fromStack(stack);
template.hasResourceProperties("AWS::EMRServerless::Application", {
ReleaseLabel: "emr-6.11.0",
Type: "SPARK",
});
template.resourceCountIs("AWS::IAM::Role", 1);
template.hasResourceProperties("AWS::S3::Bucket", {});
});

test("EMR Serverless Cluster Existing Vpc & Bucket", () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, "dummy-stack", {
Expand Down Expand Up @@ -55,7 +39,6 @@ test("EMR Serverless Cluster New Vpc & Bucket", () => {
type: "SPARK",
name: "MyEMRApp",
vpcCidr: "10.40.0.0/16",
s3Bucket: new s3.Bucket(stack, "my-dummy-bucket", {}),
});

const template = Template.fromStack(stack);
Expand All @@ -76,4 +59,36 @@ test("EMR Serverless Cluster New Vpc & Bucket", () => {
template.resourceCountIs("AWS::EC2::Route", 6);
template.resourceCountIs("AWS::EC2::InternetGateway", 1);
template.resourceCountIs("AWS::EC2::VPCGatewayAttachment", 1);
template.resourceCountIs("AWS::S3::Bucket", 1);
});

test("Vpc Cidr or Id must be provided", () => {
const stack = new cdk.Stack();
expect(() => {
new EMRServerlessCluster(stack, "Stage", { name: "EmrApp", releaseLabel: "emr-6.11.0", type: "SPARK" });
}).toThrowError("One of 'vpcId' or 'vpcCidr' must be provided");
});

test("Invalid Vpc Cidr: Too Large", () => {
const stack = new cdk.Stack();
expect(() => {
new EMRServerlessCluster(stack, "Stage", {
name: "EmrApp",
releaseLabel: "emr-6.11.0",
type: "SPARK",
vpcCidr: "10.0.0.0/15",
});
}).toThrowError("Vpc Cidr Range must of size >=16 and <=20");
});

test("Invalid Vpc Cidr: Too Small", () => {
const stack = new cdk.Stack();
expect(() => {
new EMRServerlessCluster(stack, "Stage", {
name: "EmrApp",
releaseLabel: "emr-6.11.0",
type: "SPARK",
vpcCidr: "10.0.0.0/21",
});
}).toThrowError("Vpc Cidr Range must of size >=16 and <=20");
});

0 comments on commit 163ed3a

Please sign in to comment.