oss-gate / workshop

OSSの開発に未参加または参加したことはあるけどまだ自信がない人を後押しするワークショップ用のリポジトリー
125 stars 548 forks source link

OSS Gateワークショップ 2016-11-26: @n-ina : serverless: 作業ログ #162

Closed n-ina closed 7 years ago

n-ina commented 7 years ago

OSS Gate へようこそ。

OSS Gateワークショップでは一人ずつ issue を作り、そこに作業ログを残しながら進めます。 過去のビギナーのものはこちらで見られます。 https://github.com/oss-gate/workshop/issues?q=is%3Aissue+is%3Aclosed

この issue 作成時点でまずやること

作業ログを書くタイミング

作業ログを書くタイミングは次のタイミングです。

作業ログに書く内容

作業ログに残すことは次のことです。「備考」以外は作業の邪魔にならないように一言でよいです。備考は作業に役立つので必要な分だけ書いてください。

ログはコメントとして追記していってください。テンプレートは次の通りです。

* 作業:(ここにやること、やっていること、やったことを書く)
* 思っていること:(今どう思っているかを書く)

備考:(必要なら必要なだけ書く。必要ないなら書かなくてもよい。)

例1(備考なし):

* 作業:インストールを始めた
* 思っていること:ドキュメント通りに進めれば大丈夫だろう

例2:

* 作業:インストールが失敗した
* 思っていること:ドキュメントに手順が足りない?

備考:エラーメッセージは次の通り

```text
XXX is not found
```

必要なファイルが足りないのかなぁ。

ふりかえり

作業ログは、ビギナーが、このワークショップを通して得るものをより増やすために重要になります。なぜなら作業ログがメンターからのフィードバックをより充実させるからです。

作業ログを元にメンターと「ふりかえり」をするタイミングがあります。「ふりかえり」では次のことをします。

メンターは次のようなフィードバックをします。これは、ビギナーとは違う視点からビギナーの行動を観察することおよびメンターの経験があるからできることです。(「ふりかえり」の前にこんなフィードバックをよろしくお願いします!とお願いすると効果が高まるので実践してみましょう。)

このように、ビギナーの作業をメンター視点で一緒に整理し、ビギナーの今後の行動に活かす活動がここでいう「ふりかえり」です。そのため、「ビギナーにとって」ログに残すべきかどうか、という視点ではなく、「とりあえずログに残す」という視点でログを残してください。これは、ビギナーが重要だと判断しなくてもメンターの視点から見たら大事なこともあるからです。

n-ina commented 7 years ago

とりあえずクイックスタート読もう https://github.com/serverless/serverless#quick-start

n-ina commented 7 years ago

インストール

$ npm install -g serverless
npm WARN peerDependencies The peer dependency eslint@^3.3.1 included from eslint-config-airbnb-base will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm WARN peerDependencies The peer dependency eslint-plugin-import@^1.13.0 included from eslint-config-airbnb-base will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
/Users/n.inagaki/.nodebrew/node/v4.4.3/bin/serverless -> /Users/n.inagaki/.nodebrew/node/v4.4.3/lib/node_modules/serverless/bin/serverless
/Users/n.inagaki/.nodebrew/node/v4.4.3/bin/sls -> /Users/n.inagaki/.nodebrew/node/v4.4.3/lib/node_modules/serverless/bin/serverless
/Users/n.inagaki/.nodebrew/node/v4.4.3/bin/slss -> /Users/n.inagaki/.nodebrew/node/v4.4.3/lib/node_modules/serverless/bin/serverless
serverless@1.2.1 /Users/n.inagaki/.nodebrew/node/v4.4.3/lib/node_modules/serverless
├── path-is-inside@1.0.2
├── is-path-cwd@1.0.0
├── exit-hook@1.1.1
├── strip-outer@1.0.0
├── is-path-inside@1.0.0
├── capture-stack-trace@1.0.0
├── caller-path@0.1.0
├── tryit@1.0.3
├── is-path-in-cwd@1.0.0
├── callsites@0.2.0
├── brace-expansion@1.1.6
├── slash@1.0.0
├── get-stdin@4.0.1
├── lowercase-keys@1.0.0
├── natural-compare@1.4.0
├── timed-out@2.0.0
├── bcrypt-pbkdf@1.0.0
├── readline2@1.0.1
├── semver-regex@1.0.0
├── diff@1.4.0
├── is-natural-number@2.1.1
├── buffer-shims@1.0.0
├── aws-sign2@0.6.0
├── is-redirect@1.0.0
├── abbrev@1.0.9
├── get-proxy@1.1.0
├── tunnel-agent@0.4.3
├── array-union@1.0.2
├── restore-cursor@1.0.1
├── arrify@1.0.1
├── babel-code-frame@6.16.0
├── decamelize@1.2.0
├── browser-stdout@1.3.0
├── ansi-regex@2.0.0
├── forever-agent@0.6.1
├── cli-cursor@1.0.2
├── escape-string-regexp@1.0.5
├── is-resolvable@1.0.0
├── ini@1.3.4
├── has-ansi@2.0.0
├── decompress-targz@4.0.0
├── longest@1.0.1
├── filename-reserved-regex@1.0.0
├── number-is-nan@1.0.1
├── lodash.isarguments@3.1.0
├── is-relative@0.1.3
├── oauth-sign@0.8.2
├── pinkie-promise@2.0.1
├── prepend-http@1.0.4
├── lodash.endswith@4.2.1
├── module-not-found-error@1.0.1
├── strip-ansi@3.0.1
├── user-home@2.0.0
├── strip-bom@3.0.0
├── resolve-from@1.0.1
├── pkg-dir@1.0.0
├── pkg-up@1.0.0
├── trim-repeated@1.0.0
├── right-align@0.1.3
├── has-flag@1.0.0
├── url-parse-lax@1.0.0
├── path-exists@2.1.0
├── normalize-path@2.0.1
├── align-text@0.1.4
├── ansi-escapes@1.4.0
├── ansi-styles@2.2.1
├── array-uniq@1.0.3
├── create-error-class@3.0.2
├── del@2.2.2
├── decompress-tar@4.1.0
├── code-point-at@1.1.0
├── camelcase@1.2.1
├── decompress-unzip@4.0.1
├── figures@1.7.0
├── fast-levenshtein@2.0.5
├── find-up@1.1.2
├── caw@2.0.0
├── is-fullwidth-code-point@1.0.0
├── duplexer3@0.1.4
├── download@5.0.2
├── inflight@1.0.6
├── fill-keys@1.0.2
├── is-absolute@0.1.7
├── file-type@3.8.0
├── decompress@4.0.0
├── imurmurhash@0.1.4
├── filenamify@1.2.1
├── globby@5.0.0
├── contains-path@0.1.0
├── ignore@3.2.0
├── is-stream@1.1.0
├── lodash._baseassign@3.2.0
├── lazy-cache@1.0.4
├── path-is-absolute@1.0.1
├── lodash._getnative@3.9.1
├── lodash.create@3.1.1
├── kind-of@3.0.4
├── lodash._basecreate@3.0.3
├── lodash._basecopy@3.0.1
├── lodash.keys@3.1.2
├── object-assign@4.1.0
├── lodash.isarray@3.0.4
├── lodash._isiterateecall@3.0.9
├── is-retry-allowed@1.1.0
├── os-homedir@1.0.2
├── unzip-response@2.0.1
├── onetime@1.1.0
├── punycode@1.3.2
├── pinkie@2.0.4
├── slice-ansi@0.0.4
├── got@6.5.0
├── supports-color@2.0.0
├── pify@2.3.0
├── string-width@1.0.2
├── pluralize@1.2.1
├── wrappy@1.0.2
├── repeat-string@1.6.1
├── node-status-codes@2.0.1
├── window-size@0.1.0
├── sum-up@1.0.3
├── write@0.2.1
├── once@1.4.0
├── chalk@1.1.3
├── decompress-tarbz2@4.1.0
├── zip-stream@1.1.0
├── combined-stream@1.0.5
├── require-uncached@1.0.3
├── minimatch@3.0.3
├── yauzl@2.6.0
├── lodash.find@4.6.0
├── lodash.cond@4.5.2
├── lodash.findindex@4.6.0
├── assert-plus@0.2.0
├── string_decoder@0.10.31
├── assertion-error@1.0.2
├── balanced-match@0.4.2
├── amdefine@1.0.1
├── component-emitter@1.2.1
├── inherits@2.0.3
├── center-align@0.1.3
├── methods@1.1.2
├── merge-descriptors@1.0.1
├── is-property@1.0.2
├── pend@1.2.0
├── archiver-utils@1.3.0
├── form-data@1.0.0-rc3
├── caseless@0.11.0
├── fs.realpath@1.0.0
├── co@4.6.0
├── growl@1.9.2
├── interpret@1.0.1
├── file-entry-cache@2.0.0
├── jsprim@1.3.1
├── get-stream@2.3.1
├── is-typedarray@1.0.0
├── js-tokens@2.0.0
├── mime-types@2.1.12
├── mute-stream@0.0.5
├── globals@9.14.0
├── commander@2.8.1
├── estraverse@4.2.0
├── graceful-readlink@1.0.1
├── sax@1.1.5
├── json3@3.3.2
├── builtin-modules@1.1.1
├── util-deprecate@1.0.2
├── ms@0.7.1
├── process-nextick-args@1.0.7
├── log-driver@1.2.5
├── delayed-stream@1.0.0
├── cookiejar@2.0.6
├── deep-extend@0.4.1
├── stack-trace@0.0.9
├── damerau-levenshtein@1.0.3
├── type-check@0.3.2
├── core-util-is@1.0.2
├── crc32-stream@1.0.0
├── flat-cache@1.2.1
├── xml2js@0.4.15
├── rimraf@2.5.4
├── strip-dirs@1.1.1
├── strip-json-comments@1.0.4
├── generate-object-property@1.2.0
├── stringstream@0.0.5
├── ieee754@1.1.8
├── generate-function@2.0.0
├── uglify-to-browserify@1.0.2
├── buffer-crc32@0.2.5
├── jsonify@0.0.0
├── graceful-fs@4.1.9
├── is-buffer@1.1.4
├── eslint-import-resolver-node@0.2.3
├── klaw@1.3.0
├── concat-map@0.0.1
├── jsonfile@2.4.0
├── tar-stream@1.5.2
├── jsonpointer@4.0.0
├── type-detect@1.0.0
├── cryptiles@2.0.5
├── native-promise-only@0.8.1
├── jsbn@0.1.0
├── immediate@3.0.6
├── glob@7.1.1
├── isarray@1.0.0
├── which@1.2.12
├── optionator@0.8.2
├── esutils@2.0.2
├── replaceall@0.1.6
├── has@1.0.1
├── path-loader@1.0.1
├── aws4@1.5.0
├── mime-db@1.24.0
├── encoding@0.1.12
├── isstream@0.1.2
├── progress@1.1.8
├── fd-slicer@1.0.1
├── base64-js@1.2.0
├── filesize@3.3.0
├── typedarray@0.0.6
├── levn@0.3.0
├── url@0.10.3
├── is-object@1.0.1
├── xtend@4.0.1
├── formatio@1.1.1
├── json-stringify-safe@5.0.1
├── ecc-jsbn@0.1.1
├── async@1.5.2
├── isexe@1.1.2
├── https-proxy-agent@1.0.0
├── boom@2.10.1
├── wordwrap@1.0.0
├── reduce-component@1.0.1
├── run-async@0.1.0
├── deep-is@0.1.3
├── rechoir@0.6.2
├── samsam@1.1.2
├── doctrine@1.5.0
├── function-bind@1.1.0
├── circular-json@0.3.1
├── extsprintf@1.0.2
├── agent-base@2.0.1
├── extend@3.0.0
├── caller-id@0.1.0
├── tweetnacl@0.14.3
├── lie@3.1.0
├── prelude-ls@1.1.2
├── mime@1.3.4
├── rx-lite@3.1.2
├── espree@3.3.2
├── nopt@3.0.6
├── debug@2.2.0
├── seek-bzip@1.0.5
├── sntp@1.0.9
├── esprima@2.7.3
├── through@2.3.8
├── http-signature@1.1.1
├── lolex@1.3.2
├── compress-commons@1.1.0
├── d@0.1.1
├── formidable@1.0.17
├── lcov-parse@0.0.10
├── lazystream@1.0.0
├── asn1@0.2.3
├── rc@1.1.6
├── querystring@0.2.0
├── semver@5.0.3
├── jodid25519@1.0.2
├── text-table@0.2.0
├── json-stable-stringify@1.0.1
├── sprintf-js@1.0.3
├── cli-width@2.1.0
├── hoek@2.16.3
├── qs@2.3.3
├── glob-all@3.1.0
├── verror@1.3.6
├── node-uuid@1.4.7
├── node-fetch@1.6.3
├── es6-promise@3.0.2
├── uuid@2.0.3
├── ajv-keywords@1.1.1
├── readable-stream@2.1.5
├── es6-symbol@3.1.0
├── minimist@1.2.0
├── es6-weak-map@2.0.1
├── asynckit@0.4.0
├── event-emitter@0.3.4
├── inquirer@0.12.0
├── es6-iterator@2.0.0
├── end-of-stream@1.1.0 (once@1.3.3)
├── dashdash@1.14.0 (assert-plus@1.0.0)
├── getpass@0.1.6 (assert-plus@1.0.0)
├── esrecurse@4.1.0 (estraverse@4.1.1)
├── es6-map@0.1.4
├── argparse@1.0.9
├── hawk@3.1.3
├── iconv-lite@0.4.13
├── json-refs@2.1.6 (commander@2.9.0)
├── traverse@0.6.6
├── deep-eql@0.1.3 (type-detect@0.1.1)
├── uri-js@2.1.1
├── tough-cookie@2.3.2 (punycode@1.4.1)
├── json-schema@0.2.3
├── pako@1.0.3
├── fs-extra@0.26.7
├── jmespath@0.15.0
├── escodegen@1.8.1 (estraverse@1.9.3)
├── es6-set@0.1.4
├── cliui@2.1.0 (wordwrap@0.0.2)
├── shelljs@0.6.1
├── util@0.10.3 (inherits@2.0.1)
├── source-map@0.2.0
├── js-yaml@3.6.1
├── is-my-json-valid@2.15.0
├── buffer@4.9.1
├── har-validator@2.0.6 (commander@2.9.0)
├── bluebird@3.4.6
├── acorn@4.0.3
├── bl@1.1.2 (readable-stream@2.0.6)
├── concat-stream@1.5.2 (readable-stream@2.0.6)
├── escope@3.6.0
├── sshpk@1.10.1 (assert-plus@1.0.0)
├── mkdirp@0.5.1 (minimist@0.0.8)
├── request@2.75.0 (form-data@2.0.0, qs@6.2.1)
├── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)
├── resolve@1.1.7
├── jsx-ast-utils@1.3.4
├── superagent@1.8.4 (isarray@0.0.1, readable-stream@1.0.27-1)
├── table@3.8.3 (is-fullwidth-code-point@2.0.0, string-width@2.0.0)
├── unbzip2-stream@1.0.10 (base64-js@0.0.8, buffer@3.6.0)
├── uglify-js@2.7.4 (async@0.2.10, yargs@3.10.0, source-map@0.5.6)
├── yargs@1.2.6 (minimist@0.1.0)
├── ajv@4.9.0
├── acorn-jsx@3.0.1 (acorn@3.3.0)
├── crypto-browserify@1.0.9
├── handlebars@4.0.6 (source-map@0.4.4)
├── archiver@1.1.0 (async@2.1.1)
├── moment@2.15.1
├── eslint-plugin-import@1.16.0 (doctrine@1.3.0)
├── eslint@3.11.0 (shelljs@0.7.5)
├── eslint-config-airbnb-base@5.0.3
├── aws-sdk@2.6.8
├── es5-ext@0.10.12
├── xmlbuilder@2.6.2 (lodash@3.5.0)
├── lodash@4.16.4
└── core-js@2.3.0
n-ina commented 7 years ago

Credentialの設定を読む https://github.com/serverless/serverless/blob/master/docs/providers/aws/guide/credentials.md

n-ina commented 7 years ago

AWSの内容を見ながら自分のAWSアカウントで IAM の user serverless-admin を作る https://github.com/serverless/serverless/blob/master/docs/providers/aws/guide/credentials.md#amazon-web-services

Create or login to your Amazon Web Services Account and go to the Identity & Access Management (IAM) page.

Click on Users and then Create New Users. Enter a name in the first field to remind you this User is the Framework, like serverless-admin. Then click Create. Later, you can create different IAM Users for different apps and different stages of those apps. That is, if you don't use separate AWS accounts for stages/apps, which is most common.

View and copy the API Key & Secret to a temporary place. You'll need it in the next step.

In the User record in the AWS IAM Dashboard, look for Managed Policies on the Permissions tab and click Attach Policy.

In the next screen, search for and select AdministratorAccess then click Attach.

n-ina commented 7 years ago

追加したユーザのキーを .aws/credential [serverless-adminn] で追加する

[serverless-admin]
aws_secret_access_key = ***
aws_access_key_id = ***
n-ina commented 7 years ago

👆の key を export する https://github.com/serverless/serverless/blob/master/docs/providers/aws/guide/credentials.md#quick-setup

export AWS_ACCESS_KEY_ID= ***
export AWS_SECRET_ACCESS_KEY= ***
$ serverless deploy

  Serverless Error ---------------------------------------

     This command can only be run inside a service directory

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues

  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       4.4.3
     Serverless Version: 1.2.1

ダメだったのでquick-startに戻って作業を進める 😓 https://github.com/serverless/serverless#quick-start

n-ina commented 7 years ago

init 的な手続きが必要だった。そりゃそうだ。 https://github.com/serverless/serverless#create-a-service

$ cd ~
$ mkdir service
$ cd service
$ serverless create --template aws-nodejs --path my-service
Serverless: Generating boilerplate...
Serverless: Generating boilerplate in "/Users/n.inagaki/service/my-service"
 _______                             __
|   _   .-----.----.--.--.-----.----|  .-----.-----.-----.
|   |___|  -__|   _|  |  |  -__|   _|  |  -__|__ --|__ --|
|____   |_____|__|  \___/|_____|__| |__|_____|_____|_____|
|   |   |             The Serverless Application Framework
|       |                           serverless.com, v1.2.1
 -------'

Serverless: Successfully generated boilerplate for template: "aws-nodejs"

🎉

n-ina commented 7 years ago

設定は serverless.yml にあるようなので、変更する。 https://github.com/serverless/serverless#deploy-a-service

region と credential 使うかは少なくとも設定しなくちゃいけないはず。

👇のコメントアウトを外して、regionを東京に変えた。

$ vim serverless.yml
# you can overwrite defaults here
  stage: dev
  region: ap-northeast-1

いざデプロイ :point_right:

$ serverless deploy -v
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
CloudFormation - CREATE_IN_PROGRESS - AWS::CloudFormation::Stack - my-service-dev
CloudFormation - CREATE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - CREATE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - CREATE_COMPLETE - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - CREATE_COMPLETE - AWS::CloudFormation::Stack - my-service-dev
Serverless: Stack create finished...
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3 (733 B)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - my-service-dev
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Policy - IamPolicyLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Policy - IamPolicyLambdaExecution
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - CREATE_COMPLETE - AWS::IAM::Policy - IamPolicyLambdaExecution
CloudFormation - UPDATE_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - my-service-dev
CloudFormation - UPDATE_COMPLETE - AWS::CloudFormation::Stack - my-service-dev
Serverless: Stack update finished...

Service Information
service: my-service
stage: dev
region: ap-northeast-1
api keys:
  None
endpoints:
  None
functions:
  my-service-dev-hello: arn:aws:lambda:ap-northeast-1:214211776826:function:my-service-dev-hello

Stack Outputs
HelloLambdaFunctionArn: arn:aws:lambda:ap-northeast-1:214211776826:function:my-service-dev-hello
ServerlessDeploymentBucketName: my-service-dev-serverlessdeploymentbucket-pgckocy0lhb

いけたっぽい。けど、どのcredentialが使われたか分からなかったので、確認する。

n-ina commented 7 years ago

CloudFormationにStackが作られた事を確認 arn:aws:cloudformation:ap-northeast-1:214211776826:stack/my-service-dev/33321760-b382-11e6-b503-50a6866998ae

n-ina commented 7 years ago

https://github.com/serverless/serverless#deploy-function 次は、Lambda functionをデプロイする。

$ serverless deploy function -f myfunction
Serverless: Deploying function: myfunction...

  Serverless Error ---------------------------------------

     Function "myfunction" doesn't exist in this Service

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues

  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       4.4.3
     Serverless Version: 1.2.1

無いって言われた。なんて名前のfunctionがデプロイされたんだろう 🤔

functions: my-service-dev-hello: arn:aws:lambda:ap-northeast-1:214211776826:function:my-service-dev-hello

さっきの serverless deploy コマンドでデプロイされたfunctionは hello だったようだ。 serverless deploy function -f hello で試してみる

$ serverless deploy function -f hello
Serverless: Deploying function: hello...
Serverless: Packaging function: hello...
Serverless: Uploading function: hello (733 B)...
Serverless: Successfully deployed function: hello

いけた 🎉

n-ina commented 7 years ago

他のコマンドも試す

https://github.com/serverless/serverless#invoke-a-function

$serverless invoke -f hello -l
{
    "statusCode": 200,
    "body": "{\"message\":\"Go Serverless v1.0! Your function executed successfully!\",\"input\":{}}"
}
--------------------------------------------------------------------
START RequestId: 476a1b90-b384-11e6-a8a7-45bdd8f2a5bd Version: $LATEST
END RequestId: 476a1b90-b384-11e6-a8a7-45bdd8f2a5bd
REPORT RequestId: 476a1b90-b384-11e6-a8a7-45bdd8f2a5bd  Duration: 0.78 ms   Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory Used: 16 MB  

動いた。続いて log の fetch

https://github.com/serverless/serverless#fetch-function-logs

$ serverless logs -f hello -t
START RequestId: 988e7845-b383-11e6-a06a-c9664e51f46b Version: $LATEST
END RequestId: 988e7845-b383-11e6-a06a-c9664e51f46b
REPORT RequestId: 988e7845-b383-11e6-a06a-c9664e51f46b  Duration: 2.04 ms   Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory Used: 16 MB  

tail してる?っぽいので別で invoke してみる。

$ serverless invoke -f hello

  Serverless Error ---------------------------------------

     The security token included in the request is invalid.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues

  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       4.4.3
     Serverless Version: 1.2.1

ダメっぽい。

n-ina commented 7 years ago

export してなかったからだと思うので、別タブでも exportする

$ export AWS_ACCESS_KEY_ID=***
$ export AWS_SECRET_ACCESS_KEY=***
$ serverless invoke -f hello -l
{
    "statusCode": 200,
    "body": "{\"message\":\"Go Serverless v1.0! Your function executed successfully!\",\"input\":{}}"
}
--------------------------------------------------------------------
START RequestId: d4a3d3ef-b384-11e6-be1a-7d6f9a6a5860 Version: $LATEST
END RequestId: d4a3d3ef-b384-11e6-be1a-7d6f9a6a5860
REPORT RequestId: d4a3d3ef-b384-11e6-be1a-7d6f9a6a5860  Duration: 0.40 ms   Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory Used: 16 MB  
START RequestId: 6368b40e-b384-11e6-9a76-e144a5f68da5 Version: $LATEST
END RequestId: 6368b40e-b384-11e6-9a76-e144a5f68da5
REPORT RequestId: 6368b40e-b384-11e6-9a76-e144a5f68da5  Duration: 0.42 ms   Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory Used: 16 MB  

START RequestId: d11925c2-b384-11e6-923e-99893e95c161 Version: $LATEST
END RequestId: d11925c2-b384-11e6-923e-99893e95c161
REPORT RequestId: d11925c2-b384-11e6-923e-99893e95c161  Duration: 0.33 ms   Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory Used: 16 MB  

START RequestId: d4a3d3ef-b384-11e6-be1a-7d6f9a6a5860 Version: $LATEST
END RequestId: d4a3d3ef-b384-11e6-be1a-7d6f9a6a5860
REPORT RequestId: d4a3d3ef-b384-11e6-be1a-7d6f9a6a5860  Duration: 0.40 ms   Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory Used: 16 MB  

予想通り serverless logs -f hello -t は tail してくれてる様子。めちゃ便利。

クイックスタートだからだと思うのだけれど、毎回環境変数を export するのはめんどいので、どこかで設定できるといいな 🤔

n-ina commented 7 years ago

環境変数を export しなくても良くなるオプションが無いか調べる https://serverless.com/framework/docs/

n-ina commented 7 years ago

フィードバックしたい内容

https://github.com/serverless/serverless#quick-start の手順通りに進めたが、失敗する部分があった。

  1. Create a Serviceserverless create --template aws-nodejs --path my-service した
  2. Deploy a Serviceserverless deploy -v を実施した
  3. Deploy Functionserverless deploy function -f myfunction で、以下のエラーが発生した
$ serverless deploy function -f myfunction
Serverless: Deploying function: myfunction...

  Serverless Error ---------------------------------------

     Function "myfunction" doesn't exist in this Service

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues

  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       4.4.3
     Serverless Version: 1.2.1

1.で作られる、 function の名前は hello なので、 serverless deploy function -f myfunctionserverless deploy function -f hello にするべきではないか。

n-ina commented 7 years ago

フィードバックはPRで送ることにした。

forkしたリポジトリをcloneする。

$ git clone git@github.com:n-ina/serverless.git
$ cd serverless/
$ git co -b fix_quick_start
$ vim README.md 
$ git add README.md
$ git commit -m 'fix deploy function command at quick start.'
$ git push origin fix_quick_start

で、PR作ろうとしたところ、CONTRIBUTING.md読めと言ってるので読む 👀 https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md

n-ina commented 7 years ago

documentationに関する記述もあった。 https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md#improving-documentation

If you see any issues with our docs, simply open an issue or a PR.

普通にPR送ってくれて良いとの事なので作る 💪

n-ina commented 7 years ago

作った。CIが落ちているのでメンターと一緒に調べる。 https://travis-ci.org/serverless/serverless/jobs/178998705

n-ina commented 7 years ago
> serverless@1.2.1 lint /home/travis/build/serverless/serverless
> eslint .
/home/travis/build/serverless/serverless/lib/plugins/aws/info/index.js
  164:46  error  Strings must use singlequote  quotes
  192:50  error  Strings must use singlequote  quotes
  205:50  error  Strings must use singlequote  quotes

eslint で失敗していることが分かった。 ローカルで再現するか確認して、直せればまた contribute できるよね。 ということで、ローカル環境を作る事に。

n-ina commented 7 years ago
$ npm install
$ eslint .
eslint: command not found

$ node_modules/eslint/bin/eslint.js .
/Users/n.inagaki/workspace/serverless/lib/plugins/aws/info/index.js
  164:46  error  Strings must use singlequote  quotes
  192:50  error  Strings must use singlequote  quotes
  205:50  error  Strings must use singlequote  quotes

✖ 3 problems (3 errors, 0 warnings)

再現した 💡

n-ina commented 7 years ago
npm ERR! Failed at the serverless@1.2.1 lint script 'eslint .'.
npm ERR! Make sure you have the latest version of node.js and npm installed.

メンターより 「Travis の結果で、node が古い的な事言われているから、最新にして動かしてみたらどう」とアドバイスをいただいたので、nodeのバージョンを上げてやってみる。

ノードのバージョン上げ

$ brew install nvm
$ export NVM_DIR="$HOME/.nvm"
$ . "$(brew --prefix nvm)/nvm.sh"
$ nvm ls-remote
$ nvm install v7.2.0
$ node -v
v7.2.0

リトライ

$ ./node_modules/eslint/bin/eslint.js .

/Users/n.inagaki/workspace/serverless/lib/plugins/aws/info/index.js
  164:46  error  Strings must use singlequote  quotes
  192:50  error  Strings must use singlequote  quotes
  205:50  error  Strings must use singlequote  quotes

✖ 3 problems (3 errors, 0 warnings)

ダメだったので、該当コードを見に行く 🔍

n-ina commented 7 years ago

怒られていた所のバッククォートをシングルクォートに全部直す。

$ git diff
diff --git a/lib/plugins/aws/info/index.js b/lib/plugins/aws/info/index.js
index 5f73c1a..ca014b2 100644
--- a/lib/plugins/aws/info/index.js
+++ b/lib/plugins/aws/info/index.js
@@ -161,7 +161,7 @@ ${chalk.yellow('region:')} ${info.region}`;
         apiKeysMessage = apiKeysMessage.concat(`\n  ${apiKeyInfo.name}: ${apiKeyInfo.value}`);
       });
     } else {
-      apiKeysMessage = apiKeysMessage.concat(`\n  None`);
+      apiKeysMessage = apiKeysMessage.concat('\n  None');
     }

     message = message.concat(`${apiKeysMessage}`);
@@ -189,7 +189,7 @@ ${chalk.yellow('region:')} ${info.region}`;
         });
       });
     } else {
-      endpointsMessage = endpointsMessage.concat(`\n  None`);
+      endpointsMessage = endpointsMessage.concat('\n  None');
     }

     message = message.concat(endpointsMessage);
@@ -202,7 +202,7 @@ ${chalk.yellow('region:')} ${info.region}`;
         functionsMessage = functionsMessage.concat(`\n  ${f.name}: ${f.arn}`);
       });
     } else {
-      functionsMessage = functionsMessage.concat(`\n  None`);
+      functionsMessage = functionsMessage.concat('\n  None');
     }
$ ./node_modules/eslint/bin/eslint.js .
$

直ったっぽい 😄

n-ina commented 7 years ago

意気揚々とPRを作ろうとしたのだけれど、そういえばさっきPR作った時に 'fix Linting' って書いてあったな。と思い出して、 https://github.com/serverless/serverless/pull/2800 を見に行く 🏃

既にPR作られていた 😭 https://github.com/serverless/serverless/pull/2800/files

youchan commented 7 years ago

リプライ来てますね 🎉 https://github.com/serverless/serverless/pull/2802

n-ina commented 7 years ago

はい :sparkles: CI落ちる件マージして再pushしております。

kou commented 7 years ago

おつかれさまでした! 次回は2017-01-28に開催なので、ぜひメンター(あるいは再ビギナー)で参加してみてください!