Skip to content

Commit c20871e

Browse files
committed
fix: use instance profile ARN to start instance
1 parent 5a0ec27 commit c20871e

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

packages/actions/.env.default

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ AWS_REGION="YOUR-AWS-REGION"
4848
AWS_AMI_ID="ami-022e1a32d3f742bd8"
4949
# The EC2 instance role to access S3
5050
AWS_ROLE_ARN="YOUR-AWS-ROLE-ARN"
51+
# The IAM instance profile for the EC2 instance to assume
52+
AWS_INSTANCE_PROFILE_ARN="YOUR-AWS-INSTANCE-PROFILE-ARN"
5153

5254
### AUTHENTICATION ###
5355
### These configs are related to the authentication of users.

packages/actions/src/helpers/services.ts

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const getAWSVariables = (): AWSVariables => {
3434
!process.env.AWS_SECRET_ACCESS_KEY ||
3535
!process.env.AWS_REGION ||
3636
!process.env.AWS_ROLE_ARN ||
37+
!process.env.AWS_INSTANCE_PROFILE_ARN ||
3738
!process.env.AWS_AMI_ID
3839
)
3940
throw new Error(
@@ -45,6 +46,7 @@ export const getAWSVariables = (): AWSVariables => {
4546
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
4647
region: process.env.AWS_REGION || "us-east-1",
4748
roleArn: process.env.AWS_ROLE_ARN!,
49+
instanceProfileArn: process.env.AWS_INSTANCE_PROFILE_ARN!,
4850
amiId: process.env.AWS_AMI_ID!
4951
}
5052
}

packages/actions/src/helpers/vm.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const createEC2Instance = async (
153153
diskType: DiskTypeForVM
154154
): Promise<EC2Instance> => {
155155
// Get the AWS variables.
156-
const { amiId, roleArn } = getAWSVariables()
156+
const { amiId, instanceProfileArn } = getAWSVariables()
157157

158158
// Parametrize the VM EC2 instance.
159159
const params: RunInstancesCommandInput = {
@@ -163,7 +163,7 @@ export const createEC2Instance = async (
163163
MinCount: 1,
164164
// nb. to find this: iam -> roles -> role_name.
165165
IamInstanceProfile: {
166-
Arn: roleArn
166+
Arn: instanceProfileArn
167167
},
168168
// nb. for running commands at the startup.
169169
UserData: Buffer.from(commands.join("\n")).toString("base64"),

packages/actions/src/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type AWSVariables = {
2525
secretAccessKey: string
2626
region: string
2727
roleArn: string
28+
instanceProfileArn: string
2829
amiId: string
2930
}
3031

packages/backend/.default.env

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ AWS_CEREMONY_BUCKET_POSTFIX="-ph2-ceremony"
1616
AWS_AMI_ID="ami-022e1a32d3f742bd8"
1717
# The EC2 instance role to access S3
1818
AWS_ROLE_ARN="YOUR-AWS-ROLE-ARN"
19+
# The IAM instance profile for the EC2 instance to assume
20+
AWS_INSTANCE_PROFILE_ARN="YOUR-AWS-INSTANCE-PROFILE-ARN"
1921
# The SNS topic ARN to publish notifications
2022
AWS_SNS_TOPIC_ARN="YOUR-AWS-SNS-TOPIC-ARN"
2123

0 commit comments

Comments
 (0)