我在EC2 / ECS环境中部署无服务器服务时遇到问题。
由于我正在EC2 / ECS环境中进行部署,因此需要使用credential_source
来访问实例iam角色。 (〜/ .aws / credentials上没有文件)
## ~/.aws/config
[profile dev]
role_arn = arn:aws:iam::XXXXXXXXXXXX:role/CrossAccount-AssumeJenkins
output = json
credential_source=EcsContainer #Ec2InstanceMetadata on EC2
region = ap-southeast-1
它正在AWS CLI上运行。
aws s3 ls --profile dev #working
但是当我尝试部署无服务器时,它无法正常工作。
#load config from ~/.aws/config
export AWS_SDK_LOAD_CONFIG=1
sls deploy --stage dev --verbose
sls deploy --stage dev --verbose --aws-profile dev #also not working
下面是错误堆栈。
Error --------------------------------------------------
Error: ENOENT: no such file or directory, open '/home/ec2-user/.aws/credentials'
at Object.openSync (fs.js:443:3)
at Object.readFileSync (fs.js:343:35)
at Object.readFileSync (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/util.js:95:26)
at IniLoader.parseFile (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:6:47)
at IniLoader.loadFrom (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:56:30)
at Config.region (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/node_loader.js:100:36)
at Config.set (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/config.js:507:39)
at Config.<anonymous> (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/config.js:342:12)
at Config.each (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/util.js:507:32)
at new Config (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/config.js:341:19)
at Object.<anonymous> (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/node_loader.js:110:14)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/lib/node_modules/serverless/node_modules/aws-sdk/lib/aws.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/lib/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:3:13)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/lib/node_modules/serverless/lib/plugins/index.js:24:3)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at PluginManager.loadAllPlugins (/usr/lib/node_modules/serverless/lib/classes/PluginManager.js:110:10)
at pluginManager.loadConfigFile.then.then (/usr/lib/node_modules/serverless/lib/Serverless.js:96:35)
From previous event:
at Serverless.init (/usr/lib/node_modules/serverless/lib/Serverless.js:94:8)
at initializeErrorReporter.then (/usr/lib/node_modules/serverless/bin/serverless.js:74:8)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:126:23)
From previous event:
at Object.<anonymous> (/usr/lib/node_modules/serverless/bin/serverless.js:64:4)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: linux
Node Version: 10.18.1
Framework Version: 1.62.0
Plugin Version: 3.3.0
SDK Version: 2.3.0
Components Core Version: 1.1.2
Components CLI Version: 1.4.0
触摸〜/ .aws / credentials之后,以下是新错误。
## ~/.aws/credentials
[default]
#no entry
这是错误堆栈。
Error --------------------------------------------------
Error: Profile dev does not exist
at Object.addProfileCredentials (/usr/lib/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:100:15)
at AwsProvider.getCredentials (/usr/lib/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:374:12)
at AwsProvider.request (/usr/lib/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:226:48)
at Variables.getValueFromCf (/usr/lib/node_modules/serverless/lib/classes/Variables.js:756:8)
at Variables.getValueFromSource (/usr/lib/node_modules/serverless/lib/classes/Variables.js:567:17)
at Variables.splitAndGet (/usr/lib/node_modules/serverless/lib/classes/Variables.js:436:17)
at _.map.match (/usr/lib/node_modules/serverless/lib/classes/Variables.js:373:41)
at arrayMap (/usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:639:23)
at Function.map (/usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:9554:14)
at Variables.populateMatches (/usr/lib/node_modules/serverless/lib/classes/Variables.js:373:14)
at Variables.populateValue (/usr/lib/node_modules/serverless/lib/classes/Variables.js:404:30)
at _.map.variable (/usr/lib/node_modules/serverless/lib/classes/Variables.js:286:12)
at arrayMap (/usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:639:23)
at Function.map (/usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:9554:14)
at Variables.populateVariables (/usr/lib/node_modules/serverless/lib/classes/Variables.js:285:14)
at Variables.populateObjectImpl (/usr/lib/node_modules/serverless/lib/classes/Variables.js:318:30)
at prepopulateService.then (/usr/lib/node_modules/serverless/lib/classes/Variables.js:199:16)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:126:23)
From previous event:
at initialCall (/usr/lib/node_modules/serverless/lib/classes/Variables.js:198:10)
at Variables.initialCall (/usr/lib/node_modules/serverless/lib/classes/Variables.js:102:12)
at Variables.populateService (/usr/lib/node_modules/serverless/lib/classes/Variables.js:196:17)
at Serverless.run (/usr/lib/node_modules/serverless/lib/Serverless.js:120:27)
at serverless.init.then (/usr/lib/node_modules/serverless/bin/serverless.js:75:30)
at /usr/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:136:16
at /usr/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:57:14
at FSReqWrap.args [as oncomplete] (fs.js:140:20)
From previous event:
at initializeErrorReporter.then (/usr/lib/node_modules/serverless/bin/serverless.js:75:8)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:126:23)
From previous event:
at Object.<anonymous> (/usr/lib/node_modules/serverless/bin/serverless.js:64:4)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: linux
Node Version: 10.18.1
Framework Version: 1.62.0
Plugin Version: 3.3.0
SDK Version: 2.3.0
Components Core Version: 1.1.2
Components CLI Version: 1.4.0