Skip to content

Commit

Permalink
create and destroy ec2
Browse files Browse the repository at this point in the history
  • Loading branch information
LiatSchulz committed Feb 5, 2024
1 parent feee056 commit cae59ed
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions .github/workflows/liat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ jobs:
- name: Check AWS Account
run: aws sts get-caller-identity

# - name: Launch EC2 Instance
# id: launch-ec2
# run: |
# INSTANCE_ID=$(aws ec2 run-instances --image-id YOUR_AMI_ID --instance-type YOUR_INSTANCE_TYPE --query 'Instances[0].InstanceId' --output text)
# echo "::set-output name=INSTANCE_ID::$INSTANCE_ID"
# aws ec2 wait instance-running --instance-ids $INSTANCE_ID
# PUBLIC_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].PublicIpAddress' --output text)
# echo "Instance ID: $INSTANCE_ID, Public IP: $PUBLIC_IP"
- name: Launch EC2 Instance
id: launch-ec2
run: |
AMI_ID=ami-019a4dd9d1bad0cec
ISNTANCE_TYPE=t3.large
INSTANCE_ID=$(aws ec2 run-instances --image-id $AMI_ID --instance-type $ISNTANCE_TYPE --query 'Instances[0].InstanceId' --output text)
echo "::set-output name=INSTANCE_ID::$INSTANCE_ID"
aws ec2 wait instance-running --instance-ids $INSTANCE_ID
PUBLIC_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].PublicIpAddress' --output text)
echo "Instance ID: $INSTANCE_ID, Public IP: $PUBLIC_IP"
# - name: Execute Commands on EC2 Instance
# run: |
Expand All @@ -49,9 +51,9 @@ jobs:
# tar -czvf artifact.tar.gz /path/to/your/files
# aws s3 cp artifact.tar.gz s3://YOUR_S3_BUCKET_NAME/path/to/upload/

# - name: Cleanup - Terminate EC2 Instance
# if: always()
# run: |
# INSTANCE_ID=${{ steps.launch-ec2.outputs.INSTANCE_ID }}
# aws ec2 terminate-instances --instance-ids $INSTANCE_ID
# aws ec2 wait instance-terminated --instance-ids $INSTANCE_ID
- name: Cleanup - Terminate EC2 Instance
if: always()
run: |
INSTANCE_ID=${{ steps.launch-ec2.outputs.INSTANCE_ID }}
aws ec2 terminate-instances --instance-ids $INSTANCE_ID
aws ec2 wait instance-terminated --instance-ids $INSTANCE_ID

0 comments on commit cae59ed

Please sign in to comment.