{"id":1515,"date":"2021-05-06T10:57:06","date_gmt":"2021-05-06T01:57:06","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/?p=1515"},"modified":"2021-05-06T12:08:37","modified_gmt":"2021-05-06T03:08:37","slug":"codeguru-python","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2021\/05\/06\/codeguru-python\/","title":{"rendered":"CodeGuru\u304cPython\u5bfe\u5fdc\u3057\u305f\u3088\u3046\u306a\u306e\u3067\u8a66\u3057\u3066\u307f\u305f"},"content":{"rendered":"

Amazon CodeGuru Reviewer \u306e Python \u30b5\u30dd\u30fc\u30c8\u306e\u4e00\u822c\u63d0\u4f9b\u3092\u958b\u59cb<\/h2>\n

\u6a5f\u68b0\u5b66\u7fd2\u306a\u3069\u306b\u3088\u308a\u958b\u767a\u30b3\u30fc\u30c9\u306e\u30ec\u30d3\u30e5\u30fc\u3092\u81ea\u52d5\u7684\u306b\u884c\u3063\u3066\u304f\u308c\u308b\u30c4\u30fc\u30eb\u3001"Amazon CodeGuru Reviewer"\u306e\u5bfe\u5fdc\u8a00\u8a9e\u306bPython\u304c\u8ffd\u52a0\u3055\u308c\u305f\u3053\u3068\u304c\u767a\u8868\u3055\u308c\u307e\u3057\u305f\u3002
\nhttps:\/\/aws.amazon.com\/jp\/about-aws\/whats-new\/2021\/04\/python-support-amazon-codeguru-reviewer-now-generally-available\/<\/a><\/p>\n

AWS\u3067\u306e\u8a2d\u5b9a\u81ea\u52d5\u5316\u306a\u3069\u3092Python\u3067\u66f8\u3044\u305fAWS Lambda\u306e\u95a2\u6570\u3067\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u591a\u304b\u3063\u305f\u306e\u3067\u3001Python\u3067\u3082CodeGuru\u306b\u3088\u3063\u3066AWS\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306b\u6e96\u3058\u305f\u6539\u5584\u70b9\u306e\u6307\u6458\u3092\u53d7\u3051\u3089\u308c\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3067\u3042\u308c\u3070\u5b09\u3057\u3044\u9650\u308a\u3067\u3059\u3002<\/p>\n

\u5b9f\u969b\u306b\u3069\u306e\u3088\u3046\u306a\u6307\u6458\u4e8b\u9805\u304c\u51fa\u3066\u304f\u308b\u306e\u304b\u78ba\u8a8d\u3059\u308b\u3079\u304f\u3001\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n

CodeCommit\u3068CodeGuru\u8a2d\u5b9a<\/h2>\n

\u81ea\u52d5\u30ec\u30d3\u30e5\u30fc\u5bfe\u8c61\u306e\u30b3\u30fc\u30c9\u5185\u5bb9<\/h3>\n

\u307e\u305a\u3001\u5206\u6790\u5bfe\u8c61\u3068\u306a\u308b\u30b3\u30fc\u30c9\u7fa4\u3092\u30b3\u30fc\u30c9\u7ba1\u7406\u30b5\u30fc\u30d3\u30b9\u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u683c\u7d0d\u3057\u307e\u3059\u3002
\nGitHub\u306a\u3069\u306e\u5916\u90e8\u30b5\u30fc\u30d3\u30b9\u3067\u3082\u5bfe\u5fdc\u3057\u3066\u3044\u308c\u3070CodeGuru\u306f\u5229\u7528\u53ef\u80fd\u306a\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306fAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u5185\u3067\u8a2d\u5b9a\u3092\u5b8c\u7d50\u3055\u305b\u3066\u3057\u307e\u3044\u305f\u304b\u3063\u305f\u306e\u3067\u3001AWS CodeCommit\u306b\u30b3\u30fc\u30c9\u3092\u7f6e\u304f\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n

\"\"<\/a>
\nServerless Framework\u7528\u306e\u30d5\u30a1\u30a4\u30eb\u306a\u3069\u3082\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u304c\u3001Python\u3067\u66f8\u304b\u308c\u305f handler.py<\/code> \u306e\u5185\u5bb9\u304c\u8a3a\u65ad\u3055\u308c\u308b\u3053\u3068\u3092\u671f\u5f85\u3057\u307e\u3059\u3002<\/p>\n

handler.py<\/code> \u306e\u5185\u5bb9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n

import json\nimport os\nimport boto3\n\ndef deactivate_access_key(access_key):\n    response = access_key.deactivate()\n    print(response)\n    HTTPStatusCode = response['ResponseMetadata']['HTTPStatusCode']\n    print("HTTPStatusCode:")\n    print(HTTPStatusCode)\n    accessKeyId = access_key.access_key_id\n    print(accessKeyId + " is deactivated.")\n    return\n\ndef main(event, context):\n    # \u74b0\u5883\u5909\u6570\u304b\u3089\u53d6\u5f97\n    targetAccessKeyUserName = os.environ['TARGET_ACCESS_KEY_USER_NAME']\n    # IAM\u306eclient\u3068resource\u4f5c\u6210\n    iamClient = boto3.client('iam')\n    iamResource = boto3.resource('iam')\n    # IAM\u30e6\u30fc\u30b6\u30fc\u306e\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u3092\u53d6\u5f97\u3057\u7121\u52b9\u5316\n    keys=iamClient.list_access_keys(UserName=targetAccessKeyUserName)\n    for key in keys['AccessKeyMetadata']:\n        access_key = iamResource.AccessKey(targetAccessKeyUserName, key['AccessKeyId'])\n        # \u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306e\u7121\u52b9\u5316\n        deactivate_access_key(access_key)\n    return\n<\/code><\/pre>\n

\u3053\u308c\u306f\u4ee5\u524d\u3001<\/p>\n

AWS\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u3092\u81ea\u52d5\u7684\u306b\u7121\u52b9\u5316\u3059\u308b\u65b9\u6cd5<\/p>\n

https:\/\/blog.mmmcorp.co.jp\/blog\/2020\/12\/09\/deactivate-aws-access-key\/<\/a><\/p>\n

\u306b\u3066\u5b9f\u88c5\u3057\u3066\u3044\u305f\u5185\u5bb9\u3067\u3001<\/p>\n