-
Notifications
You must be signed in to change notification settings - Fork 4
44 lines (43 loc) · 1.57 KB
/
create-ec2.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#This workflow is used to create a new EC2 instance in the AWS 'us-east-1' region
#
name: Create new EC2 instance
on:
workflow_dispatch:
inputs:
ec2_name:
description: 'Enter name of the EC2'
required: true
ami_id:
description: 'Enter AMI id for the EC2'
required: true
instance_type:
description: 'Enter EC2 instance type(Eg: t3.small)'
required: true
env:
AWS_REGION : ${{ secrets.AWS_REGION }}
# permission can be added at job level or workflow level
permissions:
id-token: write # This is required for requesting the JWT
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
role-session-name: samplerolesession
aws-region: ${{ env.AWS_REGION }}
- name: Create EC2 instance
run: |
aws ec2 run-instances \
--image-id ${{ github.event.inputs.ami_id }} \
--instance-type ${{ github.event.inputs.instance_type }} \
--key-name '${{ secrets.KEY_PAIR_NAME }}' \
--region us-east-1 \
--subnet-id ${{ secrets.SUBNET_ID }} \
--security-group-ids ${{ secrets.SECURITY_GROUP_ID }} \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=github_wf_${{ github.event.inputs.ec2_name }}}]' \
--iam-instance-profile Name=${{ secrets.IAM_INSTANCE_PROFILE }} \
--count 1 \
--no-verify-ssl &>/dev/null