Lambda Layers by Serverless
以下の記事を参考にLambda Layerを試してみました。
LambdaのLayerをServerless Frameworkで - Qiita
Lambda Layersとは
Layer化することによりより複雑な処理が実行できるということかな? AWS Lambda レイヤー - AWS Lambda
layer追加
serverlessのnodejs版(hello)にLayerを追加します。
Layerに追加する関数作成
$ cd my-project $ tree . ├── handler.js ├── my-layer │ └── nodejs │ └── node_modules │ └── pow │ └── index.js ├── serverless.yml
serverless.ymlを修正
cat serverless.yml layers: mylayer: path: my-layer
deploy
$ serverless deploy Serverless: Packaging service... Serverless: Excluding development dependencies... Serverless: Excluding development dependencies... Serverless: Creating Stack... Serverless: Checking Stack create progress... ..... Serverless: Stack create finished... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts... Serverless: Uploading service my-service.zip file to S3 (1.81 KB)... Serverless: Uploading service mylayer.zip file to S3 (207 B)... Serverless: Validating template... Serverless: Updating Stack... Serverless: Checking Stack update progress... .................. Serverless: Stack update finished... Service Information service: my-service stage: dev region: ap-northeast-1 stack: my-service-dev resources: 6 api keys: None endpoints: None functions: hello: my-service-dev-hello layers: mylayer: arn:aws:lambda:ap-northeast-1:881710576594:layer:mylayer:1
deployされているか確認します。
$ aws lambda list-layers { "Layers": [ { "LayerName": "mylayer", "LayerArn": "arn:aws:lambda:ap-northeast-1:881710576594:layer:mylayer", "LatestMatchingVersion": { "LayerVersionArn": "arn:aws:lambda:ap-northeast-1:881710576594:layer:mylayer:1", "Version": 1, "CreatedDate": "2019-05-04T05:00:56.274+0000" } } ] }
はじめてのServerless(AWS)
Serverless(AWS)を使ってみました。
AWS Lambda上にクローラーを設置するのがゴールです。
インストール
Serverless Getting Started Guide
$ npm install -g serverless # shell再読込 $ exec -l $SHELL # グローバルにインストールしたくない場合には--save-devオプションを付ける # ただし、パスを通すのが面倒かも $ npm install --save serverless
プロジェクト作成
Serverless Framework - AWS Lambda Guide - Quick Start
$ serverless create --template aws-nodejs --path my-service $ cd my-service $ ls handler.js serverless.yml
deploy
awscliのインストールおよびユーザー作成をしておく必要があります。 ユーザーにはadmin権限を追加しました。 必要最小限の権限については調査中です。
serverless.yml修正
regionを追加する。
$ cat serverless.yml ... region: ap-northeast-1 ...
handler.jsの修正は不要です。
deploy
作成したnodejsアプリ(handler.js)をdeployします。
$ serverless deploy Serverless: Packaging service... Serverless: Excluding development dependencies... Serverless: Creating Stack... Serverless: Checking Stack create progress... ..... Serverless: Stack create finished... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts... Serverless: Uploading service my-service.zip file to S3 (1.81 KB)... Serverless: Validating template... Serverless: Updating Stack... Serverless: Checking Stack update progress... ................ Serverless: Stack update finished... Service Information service: my-service stage: dev region: ap-northeast-1 stack: my-service-dev resources: 5 api keys: None endpoints: None functions: hello: my-service-dev-hello layers: None
deploy時に以下のエラーが出た場合には、Admin権限を追加してみてください。(xxx,yyy,zzzは適当に読み替えてください)
ServerlessError: User: arn:aws:iam::xxx:user/yyy is not authorized to perform: cloudformation:DescribeStacks on resource: arn:aws:cloudformation:ap-northeast-1:zzz:stack/my-service-dev/*
実行
$ serverless invoke -f hello { "statusCode": 200, "body": "{\n \"message\": \"Go Serverless v1.0! Your function executed successfully!\",\n \"input\": {}\n}" }
AWSコンソール
Lambda上にdeployされていることが確認できます。
リンク
はじめてのServerless(AWS)
Serverless(AWS)を使ってみました。
AWS Lambda上にクローラーを設置するのがゴールです。
インストール
Serverless Getting Started Guide
$ npm install -g serverless # shell再読込 $ exec -l $SHELL # グローバルにインストールしたくない場合には--save-devオプションを付ける # ただし、パスを通すのが面倒かも $ npm install --save-dev serverless
プロジェクト作成
Serverless Framework - AWS Lambda Guide - Quick Start
$ serverless create --template aws-nodejs --path my-service $ cd my-service $ ls handler.js serverless.yml
deploy
awscliのインストールおよびユーザー作成をしておく必要があります。 ユーザーにはadmin権限を追加しました。 必要最小限の権限については調査中です。
serverless.yml修正
regionを追加する。
$ cat serverless.yml ... region: ap-northeast-1 ...
handler.jsの修正は不要です。
deploy
作成したnodejsアプリ(handler.js)をdeployします。
$ serverless deploy Serverless: Packaging service... Serverless: Excluding development dependencies... Serverless: Creating Stack... Serverless: Checking Stack create progress... ..... Serverless: Stack create finished... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts... Serverless: Uploading service my-service.zip file to S3 (1.81 KB)... Serverless: Validating template... Serverless: Updating Stack... Serverless: Checking Stack update progress... ................ Serverless: Stack update finished... Service Information service: my-service stage: dev region: ap-northeast-1 stack: my-service-dev resources: 5 api keys: None endpoints: None functions: hello: my-service-dev-hello layers: None
deploy時に以下のエラーが出た場合には、Admin権限を追加してみてください。(xxx,yyy,zzzは適当に読み替えてください)
ServerlessError: User: arn:aws:iam::xxx:user/yyy is not authorized to perform: cloudformation:DescribeStacks on resource: arn:aws:cloudformation:ap-northeast-1:zzz:stack/my-service-dev/*
実行
$ serverless invoke -f hello { "statusCode": 200, "body": "{\n \"message\": \"Go Serverless v1.0! Your function executed successfully!\",\n \"input\": {}\n}" }
AWSコンソール
Lambda上にdeployされていることが確認できます。
リンク
AWS CodeCommitを使ってみる
Crawller開発のため以下の本のCodeCommit(2章)から写経しています。
AmazonWebServicesアプリ開発運用入門 | 戌亥 稔, 上迫 淳也, 三上 大輔, 百瀬 吉伸 |本 | 通販 | Amazon
Windows版は、403(Access Forbidden)が出た。 公式の対応も実施してみましたがうまく動きません。 * 認証情報ヘルパーと AWS CodeCommit への HTTPS 接続のトラブルシューティング - AWS CodeCommit
MacOS環境は以下のページを参照したらgit clone成功しました。 このままこの本を読むか思案中。
Selenium + Headless Chrome
Crowling環境を更新中。 まずは、Headless Chromeを使うように変更した。
Selenium + Headless Chrome
Crowling環境を更新中。 まずは、Headless Chromeを使うように変更した。