Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute serverless deploy with aws role

I am trying to deploy a simple lambda funtcion with the serverless framework. My IAM user doesn't have the necessary permissions to run cloudformation:

User: arn:aws:iam::xxx:user/xxx is not authorized to perform: cloudformation:DescribeStacks on resource: arn:aws:cloudformation:us-east-1:xxx:stack/xx

That's more or less intended, since our setup is using IAM roles to perform certain tasks. I have configured those roles in my ~/.aws/config file, and for aws cli operations I can e.g. call

aws s3 ls --profile myrole

in that way I attach all policies from the role 'myrole' to my IAM user to execute the aws-cli command.

Is there any way of doing something similar for serverless, i.e. attaching a role (not a different user) to the

serverless depoly 

statement?

If I change the role via export

AWS_PROFILE=myrole

or call

serverless deploy --aws-profile myrole

I get Error: Profile myrole does not exist even though the role is defined in /.aws/credentials and ~/.aws/config

like image 830
Stefan M Avatar asked Jul 12 '26 12:07

Stefan M


1 Answers

OK, I found a solution to get this working. Apparently you need to set AWS_SDK_LOAD_CONFIG to a truthy value, such that the Session will be created from the configuration values from the shared config (~/.aws/config) and shared credentials (~/.aws/credentials) files.

export AWS_SDK_LOAD_CONFIG=1

then execute with

serverless deploy --aws-profile myrole
like image 95
Stefan M Avatar answered Jul 14 '26 08:07

Stefan M