Skip to content

Commit

Permalink
fix(vms): remove redundant parameter on VM startup - ssh keypair
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Jun 26, 2023
1 parent c0a2922 commit 8f3dc42
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 21 deletions.
2 changes: 0 additions & 2 deletions packages/actions/.env.default
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ AWS_REGION="YOUR-AWS-REGION"
AWS_AMI_ID="ami-022e1a32d3f742bd8"
# The EC2 instance role to access S3
AWS_ROLE_ARN="YOUR-AWS-ROLE-ARN"
# The SSH key to access the EC2 instance
AWS_KEY_NAME="YOUR-AWS-SSH-KEY-NAME"

### AUTHENTICATION ###
### These configs are related to the authentication of users.
Expand Down
9 changes: 3 additions & 6 deletions packages/actions/src/helpers/ec2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export const createEC2Instance = async (
commands: string[],
instanceType: string,
amiId: string,
keyName: string,
roleArn: string,
volumeSize: number
): Promise<P0tionEC2Instance> => {
Expand All @@ -139,8 +138,6 @@ export const createEC2Instance = async (
InstanceType: instanceType, // to be determined programmatically
MaxCount: 1,
MinCount: 1,
KeyName: keyName,
// remember how to find this (iam -> roles -> role_name )
IamInstanceProfile: {
Arn: roleArn
},
Expand All @@ -150,9 +147,9 @@ export const createEC2Instance = async (
{
DeviceName: '/dev/xvda',
Ebs: {
DeleteOnTermination: true,
VolumeSize: volumeSize, // size in GB
VolumeType: 'gp2', // change this as per your needs
DeleteOnTermination: true,
VolumeSize: volumeSize, // size in GB
VolumeType: 'gp2', // change this as per your needs
},
},
],
Expand Down
5 changes: 2 additions & 3 deletions packages/actions/test/unit/ec2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ describe("VMs", () => {
it("should create an instance", async () => {
instance = await createEC2Instance(ec2, [
"echo 'hello world' > hello.txt",
"aws s3 cp hello.txt s3://p0tion-test-bucket/hello.txt"
], "t2.micro", amiId, keyName, roleArn, 8)
], "t2.micro", amiId, roleArn, 8)
expect(instance).to.not.be.undefined
// give it time to actually spin up
await sleep(250000)
Expand Down Expand Up @@ -84,7 +83,7 @@ describe("VMs", () => {
"aws s3 cp s3://p0tion-test-bucket/script_test.sh script_test.sh",
"chmod +x script_test.sh && bash script_test.sh"
]
ssmTestInstance = await createEC2Instance(ec2, userData, "t2.small", amiId, keyName, roleArn, 8)
ssmTestInstance = await createEC2Instance(ec2, userData, "t2.small", amiId, roleArn, 8)
await sleep(250000)
})
it("should run my commands", async () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/.default.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ AWS_CEREMONY_BUCKET_POSTFIX="-ph2-ceremony"
AWS_AMI_ID="ami-022e1a32d3f742bd8"
# The EC2 instance role to access S3
AWS_ROLE_ARN="YOUR-AWS-ROLE-ARN"
# The SSH key to access the EC2 instance
AWS_KEY_NAME="YOUR-AWS-SSH-KEY-NAME"

### GENERIC ###
### These configs are generic and not tied to Firebase or AWS services.
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/functions/ceremony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const setupCeremony = functions
// upload the instructions file the bucket and clean up
await uploadFileToBucketNoFile(bucketName, startupScript, vmCommands.join("\n"))

const { amiId, keyName, roleArn } = getAWSVariables()
const { amiId, roleArn } = getAWSVariables()

const vmSpecs = determineVMSpecs("32")
// as well as the VM configuration
Expand All @@ -161,7 +161,6 @@ export const setupCeremony = functions
userData,
"t3.xlarge",
amiId,
keyName,
roleArn,
30
)
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/functions/circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import {
CeremonyState,
Contribution,
blake512FromPath,
checkEC2Status,
getEC2Ip,
startEC2Instance,
stopEC2Instance,
runCommandOnEC2,
Expand Down
6 changes: 2 additions & 4 deletions packages/backend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ export const getAWSVariables = (): any => {
!process.env.AWS_ACCESS_KEY_ID ||
!process.env.AWS_SECRET_ACCESS_KEY ||
!process.env.AWS_ROLE_ARN ||
!process.env.AWS_AMI_ID ||
!process.env.AWS_KEY_NAME
!process.env.AWS_AMI_ID
)
logAndThrowError(COMMON_ERRORS.CM_WRONG_CONFIGURATION)

Expand All @@ -410,8 +409,7 @@ export const getAWSVariables = (): any => {
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
region: process.env.AWS_REGION || "us-east-1",
roleArn: process.env.AWS_ROLE_ARN!,
amiId: process.env.AWS_AMI_ID!,
keyName: process.env.AWS_KEY_NAME!
amiId: process.env.AWS_AMI_ID!
}
}

Expand Down

0 comments on commit 8f3dc42

Please sign in to comment.