In general, AWS services can be accessed using
- AWS web interface,
- API libraries in a programming language, such as
boto3for Python 3, - AWS command-line interface, i.e.
awscli.
I opted for the API library since it is
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Sid": "SendDataCW", | |
| "Effect": "Allow", | |
| "Action": [ | |
| "cloudwatch:PutMetricData", | |
| "ec2:DescribeTags", | |
| "cloudwatch:GetMetricStatistics", |
| # coding:utf-8 | |
| from elasticsearch import Elasticsearch | |
| import json | |
| # Define config | |
| host = "127.0.0.1" | |
| port = 9200 | |
| timeout = 1000 | |
| index = "index" |
| #!/bin/bash | |
| sudo yum update | |
| # AWS Monitoring Tool (Matches perfectly with an Instance) | |
| sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64 | |
| cd /home/ec2-user | |
| curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O | |
| unzip CloudWatchMonitoringScripts-1.2.2.zip | |
| rm CloudWatchMonitoringScripts-1.2.2.zip | |
| (crontab -l 2>/dev/null; echo "*/5 * * * * /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron") | crontab - | |
| # Docker, Git, Python, Nginx |
| # -*- coding: utf-8 -*- | |
| from flask import Flask, request, render_template, current_app | |
| from flask_wtf import Form | |
| from wtforms.validators import DataRequired | |
| from wtforms import SelectField, SelectMultipleField, SubmitField | |
| app = Flask(__name__) |
| #!/bin/bash | |
| # blueutil | |
| if which blueutil &> /dev/null; then | |
| echo "blueutil installed!" | |
| else | |
| echo "blueutil installing..." | |
| brew install blueutil | |
| echo "blueutil installed!" | |
| fi |
| # echo '{}' > event.json; mkdir -p libs; pip install attrs envattrs -t libs; \ | |
| # export YOUR_PREFIX_SLACK_CHANNEL=your_project-staging; \ | |
| # export YOUR_PREFIX_S3_BUCKET=pyconapac-bucket; \ | |
| # export YOUR_PREFIX_THRESHOLD=50; \ | |
| # python-lambda-local -l libs/ -f handler -t 5 lambda_pyconapac.py event.json | |
| from typing import Dict | |
| import attr | |
| import envattrs |
The goal of this document is submitting a job to AWS Batch and confirming the result in CloudWatch Logs.
Since I've worked on ap-northeast-1 region, The following examples includes this region name.