arabold / serverless-export-env

Serverless plugin to export environment variables into a .env file
MIT License
102 stars 34 forks source link

Getting `[Object object]` when trying to export function ARN #49

Open ezmiller opened 2 years ago

ezmiller commented 2 years ago

I am trying to export a function ARN that is defined in an environment variable on the provider environment:

provider:
  ...
  environment:
    BUILD_PRODUCT_FUNCTION_ARN: !GetAtt BuildProductLambdaFunction.Arn

The ARN is set correctly within the deployed environment, but the export .env reads:

BUILD_PRODUCT_FUNCTION_ARN=[object Object]

Is this a bug?

arabold commented 2 years ago

Fn::GetAtt doesn't fully work, unfortunately. As a workaround, you can define getAttMap in your serverless.yaml as described here: https://github.com/arabold/serverless-export-env#custom-resource-resolution

But I admit this should be made clearer.

eduardo3g commented 2 years ago

Do I necessarily have to mock the value with getAttMap? I'm having issues to export my AppSync GraphQLUrl with !GetAtt.

I can't just mock the URL because I use this value in my end-to-end tests. So basically my test suite deploys a stack, generates the .env file with this plugin (including the GraphQLUrl of the API deployed during the CI/CD pipeline), tests run reading the .env file and then I clean up the stack.

From my understanding the getAttMap wouldn't be a solution in this case.

Edit: it worked just fine with older versions. I'm converting my service to Serverless v3 and for that I had to upgrade the plugin to v2.1.0, and that's breaking the part to export the AppSync GraphQLUrl.

pokryfka commented 1 year ago

Do I necessarily have to mock the value with getAttMap? I'm having issues to export my AppSync GraphQLUrl with !GetAtt.

I can't just mock the URL because I use this value in my end-to-end tests. So basically my test suite deploys a stack, generates the .env file with this plugin (including the GraphQLUrl of the API deployed during the CI/CD pipeline), tests run reading the .env file and then I clean up the stack.

From my understanding the getAttMap wouldn't be a solution in this case.

Edit: it worked just fine with older versions. I'm converting my service to Serverless v3 and for that I had to upgrade the plugin to v2.1.0, and that's breaking the part to export the AppSync GraphQLUrl.

serverless-appsync-plugin v2 exports AppSync URL

https://github.com/sid88in/serverless-appsync-plugin/blob/v2.0.0-alpha.12/README.md#variables