2017-06-21 75 views
0

運行CircleCI和Claudia.js以將我的node.js代碼部署到AWS Lambda。CircleCI無法運行「克勞迪婭更新」

這裏是我的package.json(腳本部分):

"scripts": { 
    "deploy": "claudia create --handler lambda.handler --deploy-proxy-api --region eu-central-1", 
    "update": "claudia update", 
    "generate-proxy": "claudia generate-serverless-express-proxy --express-module server", 
    "test": "./node_modules/.bin/mocha --reporter spec" 
    }, 

當我跑步時:在終端

npm run update 

,我可以更新就好了。但是當我在CircleCI中運行它時失敗了。

這裏是我的CircleCI配置文件(.circleci/config.yml):

version: 1 
jobs: 
    build: 
    machine: 
     node: 
     version: 6.11 
    working_directory: ~/project 
    steps: 
     - checkout 
     - run: 
      name: install 
      command: npm install 
     - run: 
      name: test 
      command: npm run test 
    build: 
    steps: 
     - run: 
      name: generate-proxy 
      command: npm run generate-proxy 
     - run: 
      name: update 
      command: npm run update 

在CircleCI的錯誤是:

#!/bin/bash -eo pipefail 
npm run update 

> [email protected] update /home/circleci/project 
> claudia update 

loading Lambda config 
loading Lambda config lambda.getFunctionConfiguration FunctionName=xxx 
loading Lambda config lambda.setupRequestListeners 
{ CredentialsError: Missing credentials in config 
    at IncomingMessage.<anonymous> (/home/circleci/project/node_modules/aws-sdk/lib/util.js:864:34) 
    at emitNone (events.js:91:20) 
    at IncomingMessage.emit (events.js:185:7) 
    at endReadableNT (_stream_readable.js:926:12) 
    at _combinedTickCallback (internal/process/next_tick.js:74:11) 
    at process._tickDomainCallback (internal/process/next_tick.js:122:9) 
    message: 'Missing credentials in config', 
    retryable: false, 
    time: 2017-06-21T08:02:53.894Z, 
    code: 'CredentialsError', 
    originalError: 
    { message: 'Could not load credentials from any providers', 
    retryable: false, 
    time: 2017-06-21T08:02:53.894Z, 
    code: 'CredentialsError' } } 

我有一個名爲.aws /憑證文件,其中包含:

[claudia] 
aws_access_key_id = xxxxxxx 
aws_secret_access_key = xxxxxx 

編輯:

改變config.yml相匹配的CircleCI 2.0

version: 2 
jobs: 
    build: 
    working_directory: ~/emailservice 
    docker: 
     - image: circleci/node:4.8.2 
    steps: 
     - checkout 
     - run: 
      name: update-npm 
      command: 'sudo npm install -g [email protected]' 
     - restore_cache: 
      key: dependency-cache-{{ checksum "package.json" }} 
     - run: 
      name: install 
      command: npm install 
     - save_cache: 
      key: dependency-cache-{{ checksum "package.json" }} 
      paths: 
      - ./node_modules 
     - run: 
      name: test 
      command: npm run test 
     - store_artifacts: 
      path: test-results.xml 
      prefix: tests 
     - store_artifacts: 
      path: coverage 
      prefix: coverage 
     - store_test_results: 
      path: test-results.xml 
     - run: 
      name: deploy_update 
      command: npm run update 

一切正常,除了憑證之前。從CircleCI

日誌文件:

loading Lambda config 
loading Lambda config lambda.getFunctionConfiguration FunctionName=emailService 
loading Lambda config lambda.setupRequestListeners 
{ [CredentialsError: Missing credentials in config] 
    message: 'Missing credentials in config', 
    code: 'CredentialsError', 
    time: Thu Jun 22 2017 08:11:27 GMT+0000 (UTC), 
    retryable: true, 
    originalError: 
    { message: 'Could not load credentials from any providers', 
    code: 'CredentialsError', 
    time: Thu Jun 22 2017 08:11:27 GMT+0000 (UTC), 
    retryable: true, 
    originalError: 
     { message: 'Connection timed out after 1000ms', 
     code: 'TimeoutError', 
     time: Thu Jun 22 2017 08:11:27 GMT+0000 (UTC), 
     retryable: true } } } 
npm info lifecycle [email protected]~update: Failed to exec update script 
npm ERR! code ELIFECYCLE 
npm ERR! errno 1 
npm ERR! [email protected] update: `claudia update` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] update script. 
npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 

npm ERR! A complete log of this run can be found in: 
npm ERR!  /home/circleci/.npm/_logs/2017-06-22T08_11_27_089Z-debug.log 
Exited with code 1 

我一定要在AWS添加憑證地方?我仍然可以使用終端進行部署。

回答

1

這可能與CircleCI如何處理用戶有關。

我建議使用環境變量來存儲AWS訪問密鑰和祕密。

您需要添加以下環境變量:

AWS_ACCESS_KEY_ID - 作爲一種價值
AWS_SECRET_ACCESS_KEY與您的訪問密鑰 - 作爲一種價值用自己的密鑰

更多信息經由環境變量設置鍵在AWS:

http://docs.aws.amazon.com/cli/latest/userguide/cli-environment.html

更多關於在圈CI ENV變量信息

+0

謝謝,我會去的! –

+0

這似乎工作,但我有一個新問題。將繼續搜索該答案。 Thansk! –

+0

有什麼問題?隨意問,我來自Claudia團隊。此外,對於克勞迪婭相關的問題,你應該檢查我們的gitter,即。在那裏發佈stackoverflow鏈接,然後有人會跳入並嘗試回答它。 –

1

您是否將信用存儲在您在存儲庫中提到的文件中?首先,你可能不應該,這是一個安全禁止。如果你是,它需要在~/.aws/credentials。根據您當前的配置,您的整個回購站位於~/emailservice的版本中。您需要創建aws目錄,然後使用mv移動信用卡。喜歡的東西:

mkdir ~/.aws 
mv ~/emailservice/my-creds-file ~/.aws/credenials 

另外,我建議不會在你的回購文件,並使用private environment variables。在這種情況下,您需要在CircleCI的網絡用戶界面中設置變量AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY。 AWS CLI將在運行時查看並使用這些憑據。

的AWS CLI身份驗證方法,可以在這裏找到:http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

尊敬,

裏卡多ň費利西亞諾
CircleCI開發傳播者


原始響應:

我不是100%確切地知道爲什麼你正在發生的錯誤正在發生,但它像你一樣有更大的問題。該配置文件看起來並不正確。 CircleCI 1.0和2.0的概念和配置語法以不兼容的方式混合使用。我會檢查配置語法https://circleci.com/docs/並選擇您想使用哪個版本的CircleCI。

之後,無論是在這裏還是CircleCI Discuss我們都可以嘗試排除故障。

+0

感謝您的快速回答,我將對文檔進行檢查,如果我沒有解決問題,請回復您。 如果出現更多問題,我們是否應該在這裏進行討論?謝謝 –

+0

我已經編輯了我的配置文件,除了原來的問題仍然存在之外,所有的東西都可以工作。憑據錯誤。 我將用我的新配置文件編輯我的問題。 –