mooyoul / serverless-latest-layer-version

A serverless plugin that replaces 'latest' version tag to actual lambda layer version
MIT License
25 stars 9 forks source link

Cannot search the layer when using the aws profile differnt from default one #7

Closed hisato-kawaji closed 4 years ago

hisato-kawaji commented 4 years ago

The command below is failed because no layer was found while searching the layer version (though the layer exists) I did the experiments with two AWS accounts and profiles can access each environments.

This problem can represent by the resources deployed to default AWS account and the ones deployed to the other AWS account by the deploy commad bellow sls deploy --profile {your configured aws profile name} (maybe, also by the resources deployed to default region and the ones deployed to the other region)

I guess this problem cause no AWS.Config is specified the aws credential information (profile name, or credentials).

    const lambda = new Lambda({ region: layer.region });

I practically solved the problem by using the provisional environment variables with a deploy command instead of modifying this plugin.

AWS_PROFILE={profile name} sls deploy --profile {profile name}

ex.
AWS_PROFILE=dev sls deploy --profile dev

I doubt there seem be no parameters include the aws credential infomation for plugin development.

mooyoul commented 4 years ago

Ah yes, I never tested profile usage with --profile arguments, because i usually set AWS_PROFILE environment variable instead. Anyway This plugin creates a new Lambda Client and use that for calling lambda service apis to resolve layer versions. I haven't found any proper/clean way to access serverless internal AWS credentials so that's why this issue is causing.

Fortunately, Serverless plugin can receive command-line args from constructor and it can be used for fixing this issue. I can't provide you any ETA (Currently I have no spare time :() but it will be fixed in next few days!

hisato-kawaji commented 4 years ago

Thanks for your positive reply. I hope this issue will be resolved someday.

I'll continue to resolve this issue. thank you.

corydorning53 commented 4 years ago

running into this issue and i'm curious how i can resolve it with the workaround?

medikoo commented 4 years ago

I believe it'll be fixed if this plugin will rely on Framework AWS request method as below:

serverless.getProvider('aws').request("Lambda", "listLayerVersions", params);

It internally resolves AWS credentials per Framework rules

mooyoul commented 4 years ago

:tada: This issue has been resolved in version 2.1.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

mooyoul commented 4 years ago

Hello all. This issue is fixed in v2.1.1. Thanks @medikoo for the information that i needed, and others for patience in waiting.

Stay safe and Be well! <3