1

我正在运行 CircleCI 和 Claudia.js 以将我的 node.js 代码部署到 AWS Lambda。

这是我的 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

> xxx@0.1.0 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/credentials 的文件,其中包含:

[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 npm@latest'
      - 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 xxx_email_service@0.2.0~update: Failed to exec update script
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! xxx_email_service@0.2.0 update: `claudia update`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the xxx_email_service@0.2.0 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 某处添加凭证?我仍然可以使用终端进行部署。

4

2 回答 2

2

这可能与 CircleCI 处理用户的方式有关。

我建议使用环境变量来存储 AWS 访问密钥和秘密。

您需要添加以下环境变量:

AWS_ACCESS_KEY_ID- 使用您的访问密钥作为值
AWS_SECRET_ACCESS_KEY- 使用您的密钥作为值

有关通过 AWS 中的环境变量设置密钥的更多信息:http:
//docs.aws.amazon.com/cli/latest/userguide/cli-environment.html

有关 Circle CI 中环境变量的更多信息:
https ://circleci.com/docs/1.0/environment-variables/

于 2017-06-24T14:25:00.587 回答
1

您是否将凭据存储在您在存储库中提到的文件中?首先,你可能不应该,这是一个安全禁忌。如果你是,它需要在~/.aws/credentials. 根据您当前的配置,您的整个 repo 位于~/emailservice. 您需要创建aws目录,然后使用mv. 就像是:

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

或者,我建议您的存储库中没有文件并使用私有环境变量。在这种情况下,您将在 CircleCI 的 Web UI 中AWS_ACCESS_KEY_ID设置变量。AWS_SECRET_ACCESS_KEY然后,AWS CLI 将在运行时查看并使用这些凭证。

AWS CLI 身份验证方法可在此处找到:http: //docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

尊敬,

Ricardo N Feliciano
CircleCI 开发者布道者


原始回复:

我不能 100% 确定您遇到错误的确切原因,但看起来您遇到了更大的问题。该配置文件看起来根本不正确。CircleCI 1.0 和 2.0 的概念和配置语法以不兼容的方式混合在一起。我会在https://circleci.com/docs/检查配置语法,然后选择您要使用的 CircleCI 版本。

之后,无论是在此处还是在CircleCI 讨论中,我们都可以尝试进行故障排除。

于 2017-06-22T02:31:50.883 回答