Plugin doesn't get correct credential corresponding to aws profile

I have developed a serverless plugin for personal use. In the plugin, I need to get the aws account ID. So I call the AWS SDK like below:

new this.serverless.providers.aws.sdk.STS().getCallerIdentity({});

And it works perfectly until I decide to deploy my serverless to another AWS account. I add a new profile to ‘~/.aws/credentials’ and set the provider.profile to the new profile in the ‘serverless.yml’. The profile allows me to deploy and access resource to the new AWS account, but in my plugin, I am still getting the default account ID using the same call above.

Is this a bug that the aws sdk cannot resolve the credential by the aws profile from the serverless file. Or I use it wrongly?

1 Like