Create cloud-infra.yaml #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Datastream Cloud Workflow | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Install AWS CLI | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y awscli | |
aws configure set aws_access_key_id ${{ secrets.aws_access_key_id }} | |
aws configure set aws_secret_access_key ${{ secrets.aws_secret_access_key }} | |
- name: Read JSON file | |
run: | | |
curl -L -O https://github.com/CIROH-UA/ngen-datastream/blob/main/cloud/AWS/datastream/execution_dailyrun.json | |
INSTANCE_TYPE=$(jq -r '.isntance_paramters.InstanceType' ./execution_dailyrun.json) | |
SECURITY_GRP=$(jq -r '.isntance_paramters.InstanceType' ./execution_dailyrun.json) | |
REGION=$(jq -r '.region' execution_dailyrun.json) | |
- name: Create AMI | |
run: | | |
curl -L -O https://github.com/CIROH-UA/ngen-datastream/blob/main/cloud/AWS/startup_ec2.sh | |
output=$(aws ec2 run-instances --image-id resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 --instance-type $INSTANCE_TYPE region $REGION key-name datastream-github.pem security-group-ids $SECURITY_GRP --name ngen-datastream_$(env TZ=US/Eastern date +'%Y%m%d%H%M) ---user-data ./startup_ec2.sh) | |
instance_id=$(echo $output | jq -r '.Instances[0].InstanceId') | |
aws ec2 wait instance-running --instance-ids $instance_id | |
ami_output=$(aws ec2 create-image --instance-id $instance_id --name "My_AMI_Name" --region $REGION --description "My AMI Description") | |
ami_id=$(echo $ami_output | jq -r '.ImageId') | |
aws ec2 stop-instances --instance-ids $instance_id | |
echo "Created AMI: $AMI_ID" |