2017年1月16日月曜日

AWS Lambda Process exited before completing request error

  • このエントリーをはてなブックマークに追加


AWS Lambda Process exited before completing request error LambdaでRDS(mariadb)にデータをプッシュするAPIを作っています。

Nodejs sample code

var mysql = require('mysql');

exports.handler = function(event,context){

    var connection = mysql.createConnection({
      host     : 'xxx.xxx.eu-west-1.rds.amazonaws.com', //RDSのエンドポイント
      user     : 'xxxxxx', //MySQLのユーザ名
      password : 'xxxxxx', //MySQLのパスワード
      database : 'xxxxxx'
    });

    connection.connect();

    var name = event.Name
    var email = event.Email
    var birth = event.Birth

    var insert_sql = "insert into User (Name, Email, Birth) value ('" + name +"','" + email +"','" + birth + "')"
    connection.query(insert_sql, function(err, rows, fields) {
      if (err)
      {
        console.log("--err");
        console.log(err);
        throw err;
      }
    });

    connection.end(function(err) {
        context.done();
    });

}

Mac でコードをZIPする

$ mkdir lambda-func
$ cd lambda-func
$ brew install Nodejs
$ npm install mysql
$ ls
UpdateDB.js node_modules
$ zip -r lambda-func.zip UpdateDB.js node_modules/

Upload lambda-func.zip to lambda and set handler to UpdateDB.handler (UpdateDB.js  + exports.handler)

Error

RequestId: 1682cd4d-dbea-11e6-81d7-03af694d0c84 Process exited before completing request
Process exited before completing requestのエラーがよく出ています。
色々調べたのですが、原因は以下何種あります。
  • Time out DBに接続して処理に時間がかかった。
  • Memory 割り当てるMemoryが足りなかった。
    REPORT RequestId: 1682cd4d-dbea-11e6-81d7-03af694d0c84 Duration: 3658.20 ms Billed Duration: 3700 ms Memory Size: 128 MB Max Memory Used: 128 MB

解決策

[Configuration]タブでMemoryとTime outを上げる。
他の原因かもしれません。ただ言えるのは、スクリプト内でどこかでエラーになって処理終わらなくてこのエラーが出力されていると言う感じです。DebugにConsole.logをこまめに使ってデバックしましょう

2017年1月12日木曜日

AWS Centos6.5 nginx php-fpm インストール

  • このエントリーをはてなブックマークに追加


AWS Centos6.5 nginx php-fpm インストール AWSのEC2(CentOS 6.5)にnginx、PHP-fpmのインストール手順をメモしておきます。

nginx install

sudo sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
sudo yum install nginx

php-fpm install

sudo yum install php
yum list | grep php-fpm

php-fpm 設定

sudo cp -p /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.org
sudo sed -i -e 's/user = apache/user = nginx/' /etc/php-fpm.d/www.conf

sudo sed -i -e 's/group = apache/group = nginx/' /etc/php-fpm.d/www.conf

直接viで編集してもよい。ユーザー、groupをnginxに変更

nginx 設定

例:rootディレクトリを/var/www/htmlにする
sudo cp -p /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.org
以下の様な感じで変更
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /var/www/html;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /var/www/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

起動

sudo /etc/init.d/php-fpm start
sudo /etc/init.d/nginx start

自動起動を設定
sudo chkconfig nginx on
sudo chkconfig php-fpm on

動作確認

sudo echo '' > /var/www/html/phpinfo.php
この状態だと、アクセス拒否されてできないです。
AWSインスタンスで既定でiptables,ip6tablesが有効になっているからです。
無効にする
sudo /etc/init.d/iptables stop
sudo /etc/init.d/ip6tables stop
sudo chkconfig iptables off
sudo chkconfig ip6tables off
以上でnginxとphp連携できた。

2016年12月22日木曜日

Docker Internals

  • このエントリーをはてなブックマークに追加


Docker Internals

http://docker-saigon.github.io/post/Docker-Internals/
Docker関連の解説、深くてわかりやすい。メモをとっておく

Why docker

  • Image management
  • Resource Isolation
  • File System Isolation
  • Network Isolation
  • Change Management
  • Sharing
  • Process Management
  • Service Discovery (DNS since 1.10)
Written with StackEdit.

2016年8月13日土曜日

8月13日 ポケモンGO ネットワークエラー

  • このエントリーをはてなブックマークに追加


8月13日 ポケモンGO ネットワークエラー

8月13日(土曜)午後18時前後からポケモンGO障害発生している模様。
現象は下記の様な感じです。

  1. 起動したら、地図が表示され、ポケストップやジムが表示されない。あるいは時間がかかって表示される.
  2. 右下にポケモン何も表示されない。たまに表示されるが、また表示されなくなる
  3. ジムをクリックしたら、ネットワークエラー(Network Error)が表示されて、入れない
  4. ポケモンが出現しない
  5. ジムのポケモンがずっと変わっていない

キャリア回線障害、疑ったのですが、そうでもない。
サーバー、ネットワーク障害かと思っていますが、ネット上でいろいろ調べてそういった情報全くない。。。。よくわからない。

みんなどうですか?

2016年7月28日木曜日

MACでJavaバージョンを切り替える

  • このエントリーをはてなブックマークに追加


MACでJavaバージョンを切り替える Macに複数バージョンのJAVAを入れている場合の切り替え手順です。

run /usr/libexec/java_home

Java 1.8

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
#JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home

Java 1.7

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
#JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
これでインストールされている対応バージョンの最新が適用される

Edit .bash_profile

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin