Skip to content

Commit 9cc8fc4

Browse files
committed
working
1 parent 662bcd9 commit 9cc8fc4

File tree

10 files changed

+4413
-0
lines changed

10 files changed

+4413
-0
lines changed

lib/allora/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out

lib/allora/.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

lib/allora/bin/allora.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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, 'AlloraStack', {
8+
env: {
9+
region: process.env.CDK_DEFAULT_REGION || 'us-east-1',
10+
}
11+
});
12+
13+
/*
14+
15+
cdk deploy AlloraStack --profile alloralabsnode --parameters ResourceNamePrefix=Vec4AlloraWorker1 --parameters InstanceSize=t2.medium
16+
17+
*/

lib/allora/cdk.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts bin/allora.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21+
"@aws-cdk/core:checkSecretUsage": true,
22+
"@aws-cdk/core:target-partitions": [
23+
"aws",
24+
"aws-cn"
25+
],
26+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29+
"@aws-cdk/aws-iam:minimizePolicies": true,
30+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35+
"@aws-cdk/core:enablePartitionLiterals": true,
36+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
38+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
39+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
40+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
41+
"@aws-cdk/aws-route53-patters:useCertificate": true,
42+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
43+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
44+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
45+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
46+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
47+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
48+
"@aws-cdk/aws-redshift:columnId": true,
49+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
50+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
51+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
52+
"@aws-cdk/aws-kms:aliasNameRef": true,
53+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
54+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
55+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
56+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
57+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
58+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
59+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
60+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
61+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
62+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
63+
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
64+
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
65+
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
66+
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
67+
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
68+
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
69+
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
70+
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false
71+
}
72+
}

lib/allora/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+
};

lib/allora/lib/allora-stack.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
4+
import * as iam from 'aws-cdk-lib/aws-iam';
5+
// import * as sqs from 'aws-cdk-lib/aws-sqs';
6+
7+
export class AlloraStack extends cdk.Stack {
8+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
9+
super(scope, id, props);
10+
11+
// 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+
});
22+
23+
// Create VPC
24+
const vpc = new ec2.Vpc(this, 'Vec4AlloraWorker1Vpc', {
25+
maxAzs: 1,
26+
natGateways: 0,
27+
subnetConfiguration: [{
28+
cidrMask: 24,
29+
name: `Vec4AlloraWorker1PublicSubnet`,
30+
subnetType: ec2.SubnetType.PUBLIC,
31+
}]
32+
});
33+
34+
// Create and attach Internet Gateway
35+
// const igw = new ec2.CfnInternetGateway(this, 'Vec4AlloraWorker1IGW');
36+
// new ec2.CfnVPCGatewayAttachment(this, 'Vec4AlloraWorker1VpcIgwAttachment', {
37+
// vpcId: vpc.vpcId,
38+
// internetGatewayId: igw.ref,
39+
// });
40+
41+
// Security Group with inbound TCP port 9010 open
42+
const securityGroup = new ec2.SecurityGroup(this, 'Vec4AlloraWorker1SecurityGroup', {
43+
vpc,
44+
allowAllOutbound: true,
45+
description: 'Allow inbound TCP 9010',
46+
});
47+
securityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(9010), 'Allow inbound TCP 9010');
48+
49+
// EC2 Instance
50+
const instance = new ec2.Instance(this, 'Vec4AlloraWorker1Instance', {
51+
vpc,
52+
instanceType: new ec2.InstanceType(instanceSizeParam.valueAsString),
53+
machineImage: ec2.MachineImage.genericLinux({
54+
'us-east-1': 'ami-04b70fa74e45c3917',
55+
}),
56+
vpcSubnets: {
57+
subnetType: ec2.SubnetType.PUBLIC,
58+
},
59+
securityGroup: securityGroup,
60+
blockDevices: [{
61+
deviceName: '/dev/sda1',
62+
volume: ec2.BlockDeviceVolume.ebs(30, {
63+
volumeType: ec2.EbsDeviceVolumeType.GP3,
64+
}),
65+
}],
66+
});
67+
68+
// Elastic IP
69+
const eip = new ec2.CfnEIP(this, 'Vec4AlloraWorker1EIP');
70+
new ec2.CfnEIPAssociation(this, 'Vec4AlloraWorker1EIPAssociation', {
71+
eip: eip.ref,
72+
instanceId: instance.instanceId,
73+
});
74+
75+
// Add Tags for resource naming convention
76+
// cdk.Tags.of(vpc).add('Name', `${resourceNamePrefixParam.valueAsString}-Vpc`);
77+
// cdk.Tags.of(securityGroup).add('Name', `${resourceNamePrefixParam.valueAsString}-SecurityGroup`);
78+
// cdk.Tags.of(instance).add('Name', `${resourceNamePrefixParam.valueAsString}-Instance`);
79+
// cdk.Tags.of(eip).add('Name', `${resourceNamePrefixParam.valueAsString}-EIP`);
80+
}
81+
}

0 commit comments

Comments
 (0)