AWS\u8acb\u6c42\u95a2\u9023\u8a2d\u5b9a\u753b\u9762<\/a>\u300d\u3067\u3067\u304d\u307e\u3059\u3002\n<\/ul>\n\u3053\u308c\u3089\u306e\u4e2d\u3067\u300c\u8acb\u6c42\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u300d\u306b\u6bce\u65e5\u3001\u6bce\u56de\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u78ba\u8a8d\u3059\u308b\u306e\u306f\u610f\u5916\u306b\u624b\u9593\u304c\u304b\u304b\u308a\u3001\u8acb\u6c42\u984d\u3092\u3059\u3050\u306b\u77e5\u308a\u305f\u3044\u5834\u5408\u3084\u8acb\u6c42\u984d\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u53d6\u308a\u8fbc\u3080\u306b\u306f\u4e0d\u5411\u304d\u3067\u3059\u3002<\/p>\n
\u307e\u305f\u3001CloudWatch\u306f\u5f53\u6708\u306e\u8acb\u6c42\u984d\u304c\u8a2d\u5b9a\u984d\u3092\u8d85\u3048\u308b\u3068\u901a\u77e5\u3057\u3066\u304f\u308c\u308b\u6a5f\u80fd\u304c\u3042\u308a\u4fbf\u5229\u306a\u4e00\u65b9\u3067\u3001\u30e1\u30c8\u30ea\u30af\u30b9\u4fdd\u5b58\u671f\u9593\u304c2\u9031\u9593\u306e\u305f\u3081\u3001\u904e\u53bb\u306e\u8acb\u6c42\u984d\u3068\u306e\u6bd4\u8f03\u3084\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u306e\u9023\u643a\u306b\u306f\u4e0d\u5411\u304d\u3067\u3059\u3002<\/p>\n
\u4e00\u65b9\u3001\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u3092S3\u30d0\u30b1\u30c3\u30c8\u306b\u51fa\u529b\u3059\u308b\u65b9\u6cd5\u306f\u6307\u5b9a\u3057\u305fS3\u30d0\u30b1\u30c3\u30c8\u306b\u51fa\u529b\u3055\u308c\u305f\u8a73\u7d30\u306a\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u304c\u534a\u6c38\u4e45\u7684\u306b\u6b8b\u3063\u3066\u3044\u304f\u305f\u3081\u3001\u904e\u53bb\u306e\u8acb\u6c42\u984d\u3068\u306e\u6bd4\u8f03\u3084\u30d7\u30ed\u30b0\u30e9\u30e0\u9023\u643a\u3068\u3068\u3066\u3082\u76f8\u6027\u304c\u826f\u3044\u3067\u3059\u3002<\/p>\n
\u4eca\u56de\u306fS3\u30d0\u30b1\u30c3\u30c8\u306b\u51fa\u529b\u3055\u308c\u305f\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u3092\u7528\u3044\u3066AWS CLI\u3067\u6307\u5b9a\u3057\u305f\u5e74\u6708\u306e\u5408\u8a08\u8acb\u6c42\u984d\u3092\u51fa\u529b\u3059\u308b\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8(\u30d0\u30c3\u30c1\u51e6\u7406\u30d7\u30ed\u30b0\u30e9\u30e0)\u3092\u5099\u5fd8\u9332\u3068\u3057\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n
AWS\u306e\u5408\u8a08\u6708\u984d\u6599\u91d1\u3092\u5e74\u6708\u6307\u5b9a\u3067\u53d6\u5f97\u3059\u308bAWS CLI\u3092\u7528\u3044\u305f\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8(\u30d0\u30c3\u30c1\u51e6\u7406\u30d7\u30ed\u30b0\u30e9\u30e0) \uff5e\u8acb\u6c42\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u753b\u9762\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u306a\u3044\u3067\u5408\u8a08\u8acb\u6c42\u984d\u3092\u78ba\u8a8d\u3059\u308b\u65b9\u6cd5\uff5e<\/h2>\n
\u57fa\u672c\u65b9\u91dd\u3068\u3057\u3066\u306f\u30b9\u30af\u30ea\u30d7\u30c8\u5185\u306e\u5909\u6570\u306b\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u304c\u51fa\u529b\u3055\u308c\u3066\u3044\u308bS3\u30d0\u30b1\u30c3\u30c8\u540d\u3092\u8a18\u8f09\u3057\u3066\u304a\u304d\u3001\u5f15\u6570\u3067\u6e21\u3055\u308c\u305f\u5e74\u6708\u306e\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u3092AWS CLI\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3001\u5408\u8a08\u8acb\u6c42\u984d\u3092\u8a72\u5f53\u306e\u884c\u304b\u3089\u53d6\u5f97\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n
AWS\u306e\u5408\u8a08\u6708\u984d\u6599\u91d1\u3092\u5e74\u6708\u6307\u5b9a\u3067\u53d6\u5f97\u3059\u308bAWS CLI\u3092\u7528\u3044\u305f\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8(\u30d0\u30c3\u30c1\u51e6\u7406\u30d7\u30ed\u30b0\u30e9\u30e0)<\/h3>\n
\u51e6\u7406\u306e\u5185\u5bb9\u306f\u57fa\u672c\u65b9\u91dd\u3068\u540c\u3058\u3067\u3059\u304c\u3001AWS CLI\u3067\u30d0\u30b1\u30c3\u30c8\u306e\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306bEU\u7cfb\u306e\u30ea\u30fc\u30b8\u30e7\u30f3\u3067\u306f\u30ea\u30fc\u30b8\u30e7\u30f3\u6307\u5b9a\u3092\u3059\u308b\u6587\u5b57\u5217\u304c\u7121\u3044\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u304c\u3042\u308b\u305f\u3081\u3001\u5404S3\u30d0\u30b1\u30c3\u30c8\u540d\u304b\u3089\u30ea\u30fc\u30b8\u30e7\u30f3\u6307\u5b9a\u3092\u3059\u308b\u6587\u5b57\u5217\u3092\u751f\u6210\u3059\u308b\u95a2\u6570\u3092\u4f5c\u6210\u3057\u3066AWS CLI\u5b9f\u884c\u6642\u306b\u4ed8\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n
\u5f53\u6708\u306e\u6982\u7b97\u5408\u8a08\u8acb\u6c42\u984d\u306b\u306f\u300cApproximately Total Cost\u300d\u3068\u8868\u793a\u3057\u3001\u5148\u6708\u4ee5\u524d\u306e\u78ba\u5b9a\u5408\u8a08\u8acb\u6c42\u984d\u306b\u306f\u300cCommitted Total Cost\u300d\u3068\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n
\r\n[magtranetwork@localhost ~]# vim check_aws_total_cost.sh\r\n<\/pre>\n\r\n#!\/bin\/bash\r\n\r\n# S3\u30d0\u30b1\u30c3\u30c8\u540d\u304b\u3089\u30ea\u30fc\u30b8\u30e7\u30f3\u30aa\u30d7\u30b7\u30e7\u30f3\u6587\u5b57\u5217\u3092\u4f5c\u6210\u3059\u308b\u95a2\u6570\r\n# \\`bucket_region ${BUCKET}\\`\r\nbucket_region () {\r\n REGION=`aws s3api get-bucket-location --output text --bucket ${1}`\r\n if [ "${REGION}" = "None" -o "${REGION}" = "" ]; then\r\n REGION_STR=""\r\n else\r\n REGION_STR="--region ${REGION}"\r\n fi\r\n echo ${REGION_STR}\r\n}\r\n\r\n#\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u3092\u51fa\u529b\u3057\u3066\u3044\u308bS3\u30d0\u30b1\u30c3\u30c8\u540d\r\n#\u81ea\u5206\u306e\u74b0\u5883\u306b\u5fdc\u3058\u3066\u9069\u5b9c\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002\r\nBUCKET_NAME="your-billing-report"\r\n\r\nMONTH_STR=$1\r\n\r\n#macOS\u306e\u5834\u5408\u306fgdate\u30b3\u30de\u30f3\u30c9\u3067\u65e5\u4ed8\u3092\u6271\u3046\r\nif [ "$(uname)" == 'Darwin' ]; then\r\n DATECMD=gdate\r\nelse\r\n DATECMD=date\r\nfi\r\n\r\n#\u5f15\u6570\u304c\u306a\u3044\u5834\u5408\u306f\u5f53\u6708\u3092\u6307\u5b9a\r\nif [ "${MONTH_STR}" = "" ]; then\r\n MONTH_STR=`${DATECMD} +"%Y-%m"`\r\nelse\r\n #\u5f15\u6570\u306e\u5f62\u5f0f\u304c\u9055\u3046\u5834\u5408\u306f\u7d42\u4e86\u3002\r\n IS_MONTH_STR=`echo "${MONTH_STR}" | grep '[0-9]\\{4\\}-[0-9]\\{2\\}' | wc -l | sed 's\/ \/\/g' | sed 's\/\\t\/\/g' | tr -d '\\n'`\r\n \r\n if [ "$IS_MONTH_STR" != "1" ]; then\r\n echo "Usage: $(basename $0) [MONTH_STR(ex. 2017-01)]"\r\n exit 1\r\n fi\r\nfi\r\n\r\n#\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u540d\u3092AWS CLI\u3067\u53d6\u5f97\r\nFILE_NAME=`aws s3 \\`bucket_region ${BUCKET_NAME}\\` ls s3:\/\/${BUCKET_NAME}\/ | grep "aws-billing-csv-${MONTH_STR}.csv" | awk '{print $NF}'`\r\n\r\n#\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u304c\u5b58\u5728\u3057\u306a\u3051\u308c\u3070\u7d42\u4e86\u3002\r\nif [ "${FILE_NAME}" = "" ]; then\r\n echo "Target Billing is Not Existed."\r\n exit 1\r\nfi\r\n\r\n#\u5b9f\u969b\u306b\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\r\naws s3 `bucket_region ${BUCKET_NAME}` cp s3:\/\/${BUCKET_NAME}\/${FILE_NAME} \/tmp\/ >\/dev\/null 2>&1\r\n\r\n#\u78ba\u5b9a\u5408\u8a08\u8acb\u6c42\u984d\u3092\u62bd\u51fa\r\nTOTAL_COST=`cat \/tmp\/${FILE_NAME} | sed -e 's\/,\/ \/g' | awk 'END{print $NF}' | sed -e 's\/"\/\/g'`\r\n\r\nif [ "${TOTAL_COST}" = "" ]; then\r\n #\u78ba\u5b9a\u5408\u8a08\u8acb\u6c42\u984d\u304c\u306a\u3044\u5834\u5408\u306f\u6982\u7b97\u5408\u8a08\u8acb\u6c42\u984d\u3068\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u4f5c\u6210\u65e5\u4ed8\u3092\u62bd\u51fa\u3057\u3001\u7d50\u679c\u51fa\u529b\u3002\r\n TOTAL_COST=`cat \/tmp\/${FILE_NAME} | sed -e 's\/,\/ \/g' | grep '"StatementTotal"' | awk 'END{print $NF}' | sed -e 's\/"\/\/g'`\r\n DESCRIPTION=`cat \/tmp\/${FILE_NAME} | sed -e 's\/,\/ \/g' | awk 'END{print}' | sed -e 's\/"\/\/g' | sed -e 's\/EstimatedDisclaimer\/\/g' | sed -e 's\/ \/\/g' | sed -e 's\/This report reflects your estimated monthly bill for activity through approximately \/\/g'`\r\n echo "{\\"StatementTotal\\": \\"\\$${TOTAL_COST}\\", \\"Description\\": \\"Approximately Total Cost at ${DESCRIPTION}(UTC)\\"}"\r\nelse\r\n #\u78ba\u5b9a\u5408\u8a08\u8acb\u6c42\u984d\u304c\u3042\u308b\u5834\u5408\u306f\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u4f5c\u6210\u65e5\u4ed8\u3092\u62bd\u51fa\u3057\u3001\u7d50\u679c\u51fa\u529b\u3002\r\n DESCRIPTION=`aws s3 \\`bucket_region ${BUCKET_NAME}\\` ls s3:\/\/${BUCKET_NAME}\/ | grep ${FILE_NAME} | awk '{print $1 " " $2}' | sed -e 's\/-\/\\\/\/g'`\r\n if [ "$(uname)" == 'Darwin' ]; then\r\n ZONE=`${DATECMD} | awk '{print $((NF-1))}'`\r\n else\r\n ZONE=`${DATECMD} | awk '{print $NF}'`\r\n fi\r\n echo "{\\"StatementTotal\\": \\"\\$${TOTAL_COST}\\", \\"Description\\": \\"Committed Total Cost at ${DESCRIPTION}(${ZONE})\\"}"\r\nfi\r\n\r\n#\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u3092\u524a\u9664\u3002\r\nrm -f \/tmp\/${FILE_NAME}\r\n\r\n<\/pre>\nAWS\u306e\u5408\u8a08\u6708\u984d\u6599\u91d1\u3092\u5e74\u6708\u6307\u5b9a\u3067\u53d6\u5f97\u3059\u308b\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8(\u30d0\u30c3\u30c1\u51e6\u7406\u30d7\u30ed\u30b0\u30e9\u30e0)\u306e\u5b9f\u884c\u4f8b<\/h3>\n
\u5f15\u6570\u304c\u4f55\u3082\u306a\u3044\u5834\u5408\u306f\u5f53\u6708\u3068\u307f\u306a\u3057\u3066\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002
\n\u4f8b\u3048\u30702017\u5e742\u6708\u4e2d\u306b\u5b9f\u884c\u3057\u305f\u5834\u5408\u306f\u5f15\u6570\u7121\u3057\u306e\u5834\u5408\u3068\u300c2017-02\u300d\u3092\u6307\u5b9a\u3057\u305f\u5834\u5408\u306f\u540c\u3058\u7d50\u679c\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n
\r\n[magtranetwork@localhost ~]# chmod 755 check_aws_total_cost.sh\r\n[magtranetwork@localhost ~]# .\/check_aws_total_cost.sh\r\n{"StatementTotal": "$9.21", "Description": "Approximately Total Cost at 2017\/02\/09 14:57:58(UTC)"}\r\n[magtranetwork@localhost ~]# \/check_aws_total_cost.sh 2017-02\r\n{"StatementTotal": "$9.21", "Description": "Approximately Total Cost at 2017\/02\/09 14:57:58(UTC)"}\r\n[magtranetwork@localhost ~]# \/check_aws_total_cost.sh 2017-01\r\n{"StatementTotal": "$278.85", "Description": "Committed Total Cost at 2017\/02\/03 18:16:04(UTC)"}\r\n<\/pre>\n\u5fdc\u7528\u306e\u53ef\u80fd\u6027<\/h3>\n
S3\u30d0\u30b1\u30c3\u30c8\u306b\u51fa\u529b\u3055\u308c\u308bS3\u30d0\u30b1\u30c3\u30c8\u306b\u306f\u660e\u7d30\u304c\u8a18\u8f09\u3055\u308c\u305f\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u3001\u300c\u30ea\u30bd\u30fc\u30b9\u3068\u30bf\u30b0\u3092\u542b\u3080\u8a73\u7d30\u306a\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u300d\u3092\u6709\u52b9\u306b\u3057\u305f\u5834\u5408\u306b\u51fa\u529b\u3055\u308c\u308b\u30ea\u30bd\u30fc\u30b9\u306e\u30bf\u30b0\u6bce\u306e\u8acb\u6c42\u660e\u7d30\u306a\u3069\u8a73\u7d30\u306a\u8acb\u6c42\u984d\u306e\u5206\u6790\u304c\u3067\u304d\u308b\u5f62\u5f0f\u3067\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u304c\u51fa\u529b\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n
S3\u30d0\u30b1\u30c3\u30c8\u304b\u3089\u8acb\u6c42\u30ec\u30dd\u30fc\u30c8\u3092\u30c0\u30f3\u30ed\u30fc\u30c9\u3057\u3001\u6570\u5024\u3092\u89e3\u6790\u3059\u308b\u3068\u3044\u3046\u65b9\u6cd5\u306f\u3001\u30c1\u30fc\u30e0\u6bce\u306e\u30bf\u30b0\u3067\u8acb\u6c42\u984d\u3092\u96c6\u8a08\u3057\u305f\u308a\u3001\u8acb\u6c42\u984d\u3092\u30d0\u30c3\u30c1\u9023\u643a\u3057\u3066\u5148\u6708\u3068\u6bd4\u8f03\u3057\u3066\u901a\u77e5\u3057\u305f\u308a\u306a\u3069\u3001\u69d8\u3005\u306a\u30b1\u30fc\u30b9\u3067\u8acb\u6c42\u984d\u306e\u5206\u6790\u306b\u5fdc\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
AWS\u3092\u5229\u7528\u3057\u3066\u3044\u3066\u6c17\u306b\u306a\u308b\u306e\u304c\u65e5\u3005\u5f93\u91cf\u8ab2\u91d1\u3055\u308c\u308b\u8acb\u6c42\u984d\u3067\u3059\u3002 \u7279\u306b\u8907\u6570\u306eIAM\u30e6\u30fc\u30b6\u30fc\u3092AWS\u30a2\u30ab\u30a6\u30f3\u30c8\u5185\u306b\u7528\u610f\u3057\u3066\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001IAM\u30e6\u30fc\u30b6\u30fc\u306e\u30ea\u30bd\u30fc\u30b9\u306e\u4f7f\u3044\u65b9\u306b\u3088\u3063\u3066\u306f\u6570\u65e5\u78ba\u8a8d\u3057\u306a\u304b\u3063\u305f\u3060\u3051\u3067\u6599\u91d1\u304c\u8df3\u306d\u4e0a\u304c\u3063\u3066\u3057\u307e […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[3,81,85,22,79,82],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/posts\/5267"}],"collection":[{"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/comments?post=5267"}],"version-history":[{"count":2,"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/posts\/5267\/revisions"}],"predecessor-version":[{"id":5320,"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/posts\/5267\/revisions\/5320"}],"wp:attachment":[{"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/media?parent=5267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/categories?post=5267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.magtranetwork.com\/wp-json\/wp\/v2\/tags?post=5267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}