Created
June 20, 2020 21:34
-
-
Save marknca/5e8d708a784d1bad15872f65b2cecc4f to your computer and use it in GitHub Desktop.
cloud-init for Super Feed updates
This file contains hidden or 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
#! /usr/bin/env bash | |
sudo yum -y install git | |
sudo yum -y install python3 | |
sudo pip3 install boto3 | |
sudo pip3 install dateparser | |
sudo pip3 install feedparser | |
cat > /home/ec2-user/get_secret.py <<- PY_FILE | |
# Standard libraries | |
import base64 | |
import json | |
import os | |
import sys | |
# 3rd party libraries | |
import boto3 | |
from botocore.exceptions import ClientError | |
def get_secret(secret_name, region_name): | |
""" | |
Get the specified secret from the Secrets Manager | |
""" | |
secret = None | |
session = boto3.session.Session() | |
client = session.client(service_name='secretsmanager', region_name=region_name) | |
try: | |
get_secret_value_response = client.get_secret_value(SecretId=secret_name) | |
except ClientError as e: | |
print(e) | |
else: | |
if 'SecretString' in get_secret_value_response: | |
secret = get_secret_value_response['SecretString'] | |
else: | |
decoded_binary_secret = base64.b64decode(get_secret_value_response['SecretBinary']) | |
return json.loads(secret) | |
if __name__ == '__main__': | |
github_token = get_secret(secret_name="GITHUB_TOKEN", region_name="MY_PREFERRED_REGION")['GITHUB_TOKEN'] | |
print(github_token) | |
PY_FILE | |
git clone https://`python3 get_secret.py`:[email protected]/MY_GITHUB_USERNAME/MY_PRIVATE_REPO | |
python3 /home/ec2-user/REPO/bin/super-feed.py --tsv /home/ec2-user/REPO/bin/feeds/security.tsv --output /home/ec2-user/REPO/feed-security | |
python3 /home/ec2-user/REPO/bin/super-feed.py --tsv /home/ec2-user/REPO/bin/feeds/cloud.tsv --output /home/ec2-user/REPO/feed-cloud | |
python3 /home/ec2-user/REPO/bin/super-feed.py --tsv /home/ec2-user/REPO/bin/feeds/devops.tsv --output /home/ec2-user/REPO/feed-devops | |
cd website | |
git add . | |
git commit --author="MY NAME <[email protected]>" -m "Updated super feeds via AWS" | |
git push | |
aws ec2 terminate-instances --instance-ids `wget -q -O - http://169.254.169.254/latest/meta-data/instance-id` --region MY_PREFERRED_REGION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment