Skip to content

Commit 37f914c

Browse files
committed
added tests, redid project structure, added .env sample, deleted file.txt, removed dependencies from package.json, removed package-lock.json, parameterized numerous values
1 parent dd686fd commit 37f914c

File tree

9 files changed

+121
-4215
lines changed

9 files changed

+121
-4215
lines changed

lib/allora/allora.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env node
2+
import 'source-map-support/register';
3+
import * as cdk from 'aws-cdk-lib';
4+
import { AlloraStack } from './lib/allora-stack';
5+
6+
const app = new cdk.App();
7+
new AlloraStack(app, 'allora-single-node', {
8+
stackName: 'allora-single-node',
9+
env: {
10+
account: process.env.AWS_ACCOUNT_ID || "xxxxxxxxxxx",
11+
region: process.env.AWS_REGION || 'us-east-1',
12+
},
13+
amiId: process.env.AWS_AMI_ID || 'ami-04b70fa74e45c3917',
14+
instanceType: process.env.AWS_INSTANCE_TYPE || 'ami-04b70fa74e45c3917',
15+
vpcMaxAzs: Number(process.env.AWS_VPC_MAX_AZS || 1),
16+
vpcNatGateways: Number(process.env.AWS_VPC_NAT_GATEWAYS || 0),
17+
vpcSubnetCidrMask: Number(process.env.AWS_VPC_CIDR_MASK),
18+
resourceNamePrefix: process.env.AWS_RESOURCE_NAME_PREFIX || 'AlloraWorkerxVpc'
19+
});

lib/allora/bin/allora.ts

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

lib/allora/doc/assets/file.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/allora/lib/allora-stack.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,52 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
44
import * as iam from 'aws-cdk-lib/aws-iam';
55
// import * as sqs from 'aws-cdk-lib/aws-sqs';
66

7+
8+
export interface AlloraStackProps extends cdk.StackProps {
9+
amiId: string;
10+
instanceType: string;
11+
vpcMaxAzs: number;
12+
vpcNatGateways: number
13+
vpcSubnetCidrMask: number;
14+
resourceNamePrefix: string;
15+
}
16+
17+
718
export class AlloraStack extends cdk.Stack {
8-
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
19+
constructor(scope: Construct, id: string, props?: AlloraStackProps) {
920
super(scope, id, props);
1021

1122
// Parameters
12-
// const resourceNamePrefixParam = new cdk.CfnParameter(this, 'ResourceNamePrefix', {
13-
// type: 'String',
14-
// description: 'Prefix for resource names to override AWS auto-generated naming convention',
15-
// });
16-
17-
const instanceSizeParam = new cdk.CfnParameter(this, 'InstanceSize', {
18-
type: 'String',
19-
default: 't2.medium',
20-
description: 'EC2 Instance Size',
21-
});
23+
const region = props?.env?.region || 'us-east-1';
24+
const amiId = props?.amiId || 'ami-04b70fa74e45c3917';
25+
const instanceType = props?.instanceType || 't2.medium';
26+
const resourceNamePrefix = props?.resourceNamePrefix || 'AlloraWorkerx';
2227

2328
// Create VPC
24-
const vpc = new ec2.Vpc(this, 'AlloraWorkerxVpc', {
25-
maxAzs: 1,
26-
natGateways: 0,
29+
const vpc = new ec2.Vpc(this, `${resourceNamePrefix}Vpc`, {
30+
maxAzs: props?.vpcMaxAzs || 1,
31+
natGateways: typeof props?.vpcNatGateways !== 'undefined' ? props?.vpcNatGateways : 0,
2732
subnetConfiguration: [{
28-
cidrMask: 24,
29-
name: `AlloraWorkerxPublicSubnet`,
33+
cidrMask: props?.vpcSubnetCidrMask || 24,
34+
name:`${resourceNamePrefix}PublicSubnet`,
3035
subnetType: ec2.SubnetType.PUBLIC,
3136
}]
3237
});
3338

3439
// Security Group with inbound TCP port 9010 open
35-
const securityGroup = new ec2.SecurityGroup(this, 'AlloraWorkerxSecurityGroup', {
40+
const securityGroup = new ec2.SecurityGroup(this, `${resourceNamePrefix}SecurityGroup`, {
3641
vpc,
3742
allowAllOutbound: true,
3843
description: 'Allow inbound TCP 9010',
3944
});
4045
securityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(9010), 'Allow inbound TCP 9010');
4146

4247
// EC2 Instance
43-
const instance = new ec2.Instance(this, 'AlloraWorkerxInstance', {
48+
const instance = new ec2.Instance(this, `${resourceNamePrefix}Instance`, {
4449
vpc,
45-
instanceType: new ec2.InstanceType(instanceSizeParam.valueAsString),
50+
instanceType: new ec2.InstanceType(instanceType),
4651
machineImage: ec2.MachineImage.genericLinux({
47-
'us-east-1': 'ami-04b70fa74e45c3917',
52+
[region]: amiId,
4853
}),
4954
vpcSubnets: {
5055
subnetType: ec2.SubnetType.PUBLIC,
@@ -59,8 +64,8 @@ export class AlloraStack extends cdk.Stack {
5964
});
6065

6166
// Elastic IP
62-
const eip = new ec2.CfnEIP(this, 'AlloraWorkerxEIP');
63-
new ec2.CfnEIPAssociation(this, 'AlloraWorkerxEIPAssociation', {
67+
const eip = new ec2.CfnEIP(this, `${resourceNamePrefix}EIP`);
68+
new ec2.CfnEIPAssociation(this, `${resourceNamePrefix}EIPAssociation`, {
6469
eip: eip.ref,
6570
instanceId: instance.instanceId,
6671
});

0 commit comments

Comments
 (0)