简体   繁体   中英

Amazon Web Services: NoCredentialsError: Unable to locate credentials

I am using amazon web services cli. I use a makefile to to build my lambda project and upload it to aws lambda. I am on a windows machine and using powershell to call make.

I try to delete my lambda function with the following lines

AWS_PATH = /cygdrive/c/Users/TestBox/AppData/Roaming/Python/Scripts/aws
AWS_WIN_PATH = $(shell cygpath -aw ${AWS_PATH})
AWS_REGION = eu-west-2

lambda_delete:
    $(AWS_WIN_PATH) lambda delete-function --function-name LambdaTest --region $(AWS_REGION) --debug

I get this error..

NoCredentialsError: Unable to locate credentials Unable to locate credentials. You can configure credentials by running "aws configure".

Running aws configure list prints out a valid default profile.

I think the problem is because i am using gnu make installed by cygwin on a windows machine. Using powershell to call make.

So the path to credentials looks like this "cygdrive/c/users/testbox/.aws/credentials" instead "c:\\users\\testbox.aws\\credentials", when ~/.aws/credentials is evaluated by aws. I think :)

I had the same problem with the path to aws itself and had to use $(shell cygpath -aw ${AWS_PATH}) to convert it to a path windows python could use.

Is there any way to pass the credentials directly to the lambda delete-function or indirectly through a path to a file? I cant seem to think of a way because the code that searches for the credentials is internal to botocore.

Is there a way around this that you know off?

Alternative solution, consider using AWS SAM templates

Use AWS SAM templates to deploy your Lambda functions and AWS resources using CloudFormation.

  • Edit your SAM template and define your AWS resources. For example, define Lambda functions/path to your code.
  • aws cloudformation package to package and upload your local code to S3.
  • aws cloudformation deploy to provision and update AWS resources with the updated code on S3.

This would work in CMD/Powershell without the make hassle. You will also have the benefit of having your resources versioned as code and you won't need to worry about tracking or adding new AWS APIs in your make file.

More complex serverless frameworks for reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM