{"id":23167,"date":"2022-12-14T18:27:55","date_gmt":"2022-12-14T09:27:55","guid":{"rendered":"https:\/\/www.skyarch.net\/blog\/?p=23167"},"modified":"2022-12-14T18:27:55","modified_gmt":"2022-12-14T09:27:55","slug":"aws-chalice-codepipeline-%e5%88%a9%e7%94%a8%e7%92%b0%e5%a2%83%e3%81%a7-psycopg2-%e3%83%91%e3%83%83%e3%82%b1%e3%83%bc%e3%82%b8%e3%82%92%e5%b0%8e%e5%85%a5%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/aws-chalice-codepipeline-%e5%88%a9%e7%94%a8%e7%92%b0%e5%a2%83%e3%81%a7-psycopg2-%e3%83%91%e3%83%83%e3%82%b1%e3%83%bc%e3%82%b8%e3%82%92%e5%b0%8e%e5%85%a5%e3%81%99%e3%82%8b\/","title":{"rendered":"AWS Chalice + CodePipeline \u5229\u7528\u74b0\u5883\u3067 psycopg2 \u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u5c0e\u5165\u3059\u308b"},"content":{"rendered":"<h1>\u6982\u8981<\/h1>\n<p>Python \u304b\u3089 PostgreSQL \u3092\u6271\u3046\u5834\u5408\u3001\u3088\u304f <a href=\"https:\/\/pypi.org\/project\/psycopg2\/\" target=\"_blank\" rel=\"noopener\">psycopg2<\/a> \u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u7d39\u4ecb\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u305d\u306e\u307e\u307e AWS Lambda \u3067\u5229\u7528\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u52d5\u4f5c\u3057\u306a\u3044\u3001\u3068\u3044\u3046\u70b9\u3082\u591a\u304f\u306e\u6280\u8853\u30d6\u30ed\u30b0\u7b49\u3067\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001<br \/>\n\u30ed\u30fc\u30ab\u30eb\u3067\u30c7\u30d7\u30ed\u30a4\u7528\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u308b\u89e3\u6c7a\u6cd5\u304c\u63d0\u793a\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u304c\u591a\u304f\u3001<br \/>\nCodeBuild\u30fbCodePipeline \u3067\u30d3\u30eb\u30c9\u30fb\u30c7\u30d7\u30ed\u30a4\u3092\u884c\u3063\u3066\u3044\u308b\u74b0\u5883\u306b\u3064\u3044\u3066\u306f\u3042\u307e\u308a\u89e6\u308c\u3089\u308c\u3066\u3044\u306a\u3044\u6c17\u304c\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u66f4\u306b\u3001\u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u5c0e\u5165\u3057\u3088\u3046\u3068\u3057\u305f\u74b0\u5883\u304c AWS Chalice \u3067\u30d3\u30eb\u30c9\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3082\u3042\u308a\u3001<br \/>\nChalice \u3082\u4f7f\u3044\u521d\u3081\u3060\u3063\u305f\u79c1\u306f\u305d\u308c\u306a\u308a\u306b\u82e6\u52b4\u3057\u305f\u899a\u3048\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u4eca\u56de\u306f AWS Chalice + CodeBuild + CodePipeline \u3067\u30d3\u30eb\u30c9\u30fb\u30c7\u30d7\u30ed\u30a4\u3092\u884c\u3063\u3066\u3044\u308b\u74b0\u5883\u5411\u3051\u306b<br \/>\npsycopg2 \u3092\u5c0e\u5165\u3057\u305f\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h1>\u5b9f\u88c5\u65b9\u6cd5<\/h1>\n<p>\u30d3\u30eb\u30c9\u30fb\u30c7\u30d7\u30ed\u30a4\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a Pipeline \u3092\u4f7f\u3063\u3066\u3044\u307e\u3057\u305f\u3002<br \/>\nBuild \u30b9\u30c6\u30fc\u30b8\u3067 chalice package \u3092\u5b9f\u884c\u3057CloudFormation \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2022\/12\/chalice-pipeline-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-23168\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2022\/12\/chalice-pipeline-1.png\" alt=\"\" width=\"551\" height=\"271\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2022\/12\/chalice-pipeline-1.png 551w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2022\/12\/chalice-pipeline-1-300x148.png 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/a>\n<p>psycopg2 \u3092\u5c0e\u5165\u3059\u308b\u305f\u3081\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a buildspec \u3092\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n<pre>version: 0.2\nartifacts:\n  discard-paths: no\n  files:\n    - '**\/*'\nphases:\n  install:\n    runtime-versions:\n      python: 3.9\n    commands:\n      - pip install --upgrade chalice\n  build:\n    commands:\n      - git clone https:\/\/github.com\/jkehler\/awslambda-psycopg2.git\n      - mv -v awslambda-psycopg2\/psycopg2-3.9 vendor\/psycopg2\n      - pip install -r requirements.txt -t vendor\/\n      - chalice --debug package . --template-format yaml\n<\/pre>\n<p>GitHub \u306e <a href=\"https:\/\/github.com\/jkehler\/awslambda-psycopg2\" target=\"_blank\" rel=\"noopener\">awslambda-psycopg2<\/a> \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092 clone \u3057\u3066\u3001<br \/>\n\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u5185\u306e <code>psycopg2-3.9<\/code> (python3.9 \u7528\u306e psycopg2 \u304c\u683c\u7d0d\u3055\u308c\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea) \u3092 <code>vendor\/<\/code> \u4ee5\u4e0b\u306b\u914d\u7f6e\u3057\u307e\u3059\u3002<\/p>\n<p>Chalice \u306e\u6a5f\u80fd\u3067\u3001<code>vendor\/<\/code> \u914d\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u3082 Lambda \u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306b\u542b\u307e\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/aws.github.io\/chalice\/topics\/packaging.html#rd-party-packages\" target=\"_blank\" rel=\"noopener\">App Packaging - 3rd Party Packages<\/a><\/p>\n<p>\u3053\u3061\u3089\u306e\u8a2d\u5b9a\u3067\u30d3\u30eb\u30c9\u3059\u308b\u3068\u3001Lambda \u304b\u3089 psycopg2 \u304c\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\uff01<\/p>\n<h1>\u3046\u307e\u304f\u3044\u304b\u306a\u304b\u3063\u305f\u65b9\u6cd5<\/h1>\n<p>\u4e0a\u8a18\u65b9\u6cd5\u306b\u305f\u3069\u308a\u7740\u304f\u307e\u3067\u306b\u30c8\u30e9\u30a4\u3057\u305f\u5185\u5bb9\u3067\u3059\u3002<br \/>\n\u904e\u53bb\u306e\u30ed\u30b0\u304c\u6b8b\u3063\u3066\u304a\u3089\u305a\u3069\u3046\u3046\u307e\u304f\u3044\u304b\u306a\u304b\u3063\u305f\u304b\u306f\u5b9a\u304b\u3067\u306a\u3044\u306e\u3067\u3059\u304c\u3001<br \/>\n\u304a\u305d\u3089\u304f\u3001\u30d3\u30eb\u30c9(\u30d1\u30c3\u30b1\u30fc\u30b8\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb)\u307e\u3067\u306f\u5b8c\u4e86\u3059\u308b\u304c\u5b9f\u969b\u306b Lambda \u3092 Invoke \u3057\u305f\u969b\u306b\u4ee5\u4e0b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3044\u305f\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/36103034\/importerror-no-module-named-psycopg2-psycopg\" target=\"_blank\" rel=\"noopener\">ImportError: No module named 'psycopg2._psycopg'<\/a><\/p>\n<h2>(1) pip \u3067 psycopg2 \u3092\u8ffd\u52a0<\/h2>\n<p>requirements.txt \u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u884c\u3092\u8ffd\u52a0\u3057\u3001pip install \u3067 psycopg2 \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre>psycopg2 == 2.9.5\n<\/pre>\n<p>\u3053\u3061\u3089\u306e\u65b9\u6cd5\u306f\u591a\u304f\u306e\u6280\u8853\u30d6\u30ed\u30b0\u7b49\u3067\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u306b\u6a5f\u80fd\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/pypi.org\/project\/psycopg2\/\" target=\"_blank\" rel=\"noopener\">psycopg2<\/a><\/p>\n<h2>(2) pip \u3067 psycopg2 \u3092\u8ffd\u52a0<\/h2>\n<p>requirements.txt \u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u884c\u3092\u8ffd\u52a0\u3057\u3001pip install \u3067 awslambda-psycopg2 \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre>awslambda-psycopg2 == 1.0.2\n<\/pre>\n<p>AWS Lambda \u7528\u306e psycopg2 \u306a\u306e\u3067\u6b63\u5e38\u306b\u52d5\u4f5c\u3059\u308b\u304b\u3068\u601d\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u305d\u3046\u306f\u306a\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/pypi.org\/project\/awslambda-psycopg2\/\" target=\"_blank\" rel=\"noopener\">awslambda-psycopg2<\/a><\/p>\n<p>\u5171\u540c\u8457\u8005: \u795e\u6d25<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 Python \u304b\u3089 PostgreSQL \u3092\u6271\u3046\u5834\u5408\u3001\u3088\u304f psycopg2 \u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u7d39\u4ecb\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u305d\u306e\u307e\u307e AWS Lambda \u3067\u5229\u7528\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u52d5\u4f5c\u3057\u306a\u3044\u3001\u3068\u3044\u3046\u70b9\u3082\u591a\u304f\u306e\u6280&#8230;<\/p>\n","protected":false},"author":60,"featured_media":23164,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/www.skyarch.net\/blog\/?p=23167","footnotes":""},"categories":[20,1020],"tags":[102,659,383],"class_list":{"0":"post-23167","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-aws","8":"category-ci-cd","9":"tag-aws","10":"tag-aws-codebuild","11":"tag-aws-codepipeline","12":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/23167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/60"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=23167"}],"version-history":[{"count":6,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/23167\/revisions"}],"predecessor-version":[{"id":23740,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/23167\/revisions\/23740"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/23164"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=23167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=23167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=23167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}