Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Lambda cross-env variables / secrets #13087

Closed
redjonzaci opened this issue Aug 8, 2023 · 9 comments
Closed

Automatic Lambda cross-env variables / secrets #13087

redjonzaci opened this issue Aug 8, 2023 · 9 comments
Labels
multienv Issues tied to multiple environment feature in the CLI pending-triage Issue is pending triage question General question

Comments

@redjonzaci
Copy link
Contributor

Amplify CLI Version

12.2.3

Question

I tried amplify update function and added an environment secret.
I thought that it would automatically be added to any new env I created, but it didn't.
Now the problem is that we only use PR preview environments and the build fails because the environment secret has no value for this new env.
What would be the suggested approach to use an environment secret in every env,
without having to manually add it whenever a new env is created?

@redjonzaci redjonzaci added pending-triage Issue is pending triage question General question labels Aug 8, 2023
@ykethan ykethan added the multienv Issues tied to multiple environment feature in the CLI label Aug 9, 2023
@ykethan
Copy link
Member

ykethan commented Aug 9, 2023

Hey @redjonzaci, this is currently not supported in Amplify CLI. As this would pose security issues in your environment.
If you would like to still implement this feature, I would suggest utilizing Amplify hooks with the AWS SDK like

  1. creating a pre-push hook to read SSM parameters by path prefix with the env you want to copy from.
  2. then create SSM Parameters 1:1 with the PR Preview env name
    documentation: https://docs.amplify.aws/cli/reference/ssm-parameter-store/

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Aug 9, 2023
@redjonzaci
Copy link
Contributor Author

Hey @ykethan thanks for the response!
If I am creating new envs only when I create new PRs, would the solution you are describing work so that my first build doesn't fail and then the env secret would be set on the Lambda?

I think I understand that we could set the secrets on a "main" env and then on each new PR copy those, but how would the Lambda access them? Or is that done automatically, when secrets with that Lambda's name exist in the env?

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Aug 17, 2023
@ykethan
Copy link
Member

ykethan commented Aug 17, 2023

Hey @redjonzaci, the permissions for SSM access is generated with the env cfn parameter. To mitigate the build failures you could try setting the Point all Pull Requests for this branch to an existing environment which should build the preview on a existing env.

related: #12950

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Aug 17, 2023
@redjonzaci
Copy link
Contributor Author

@ykethan I got a little confused by the answer, and I couldn't find the "Point all Pull Requests" option,
but for now, we will create a SSM parameter manually and then make a request to retrieve it whenever we need it.

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Aug 20, 2023
@ykethan
Copy link
Member

ykethan commented Aug 21, 2023

@redjonzaci the Point all Pull Requests for this branch to an existing environment should be availble in the AWS Amplify console under App settings -> Preview -> select a branch -> Click on Manage, the option should show in a popup.

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Aug 21, 2023
@josefaidt
Copy link
Contributor

Hey @redjonzaci are you still experiencing this? Were you able to successfully set up and use secrets/env vars in SSM for PR previews?

@redjonzaci
Copy link
Contributor Author

@ykethan I got a little confused by the answer, and I couldn't find the "Point all Pull Requests" option, but for now, we will create a SSM parameter manually and then make a request to retrieve it whenever we need it.

Hey @josefaidt, we settled on this solution, so for the moment, it's okay.

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Sep 12, 2023
@ykethan
Copy link
Member

ykethan commented Sep 12, 2023

@redjonzaci thank you for the confirmation. closing the issue, please feel free in reaching out to us again.

@ykethan ykethan closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multienv Issues tied to multiple environment feature in the CLI pending-triage Issue is pending triage question General question
Projects
None yet
Development

No branches or pull requests

3 participants