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

How to control resources conditional on which environment Amplify is deploying to #13860

Open
mishabruml opened this issue Jul 19, 2024 · 3 comments
Labels
feature-request Request a new feature platform-config Issues related to configuring project settings

Comments

@mishabruml
Copy link

Amplify CLI Version

12.12.4

Question

Hi there,

I've got a multi-environment project built with Amplify 12.12.4, Gen 1. Each environment (dev, sandbox, prod) deploys into it's own AWS account.

The project is basically hosting an s3-and-cloudfront site with cognito auth. The project is hooked up to be using amplify hosting/CI just like in this guide https://docs.amplify.aws/gen1/react/deploy-and-host/deployment/deploy-static-site-github/#deploy-your-app-to-aws-amplify

We have a requirement for a cognito pre-authentication lambda trigger to run some custom check before sign-in, but we only need this in prod.

I have successfully configured the lambda, but on all 3 environments; I only need it on prod. I can't find an straightforward way of configuring this through code.

It seems like based on answers such as #4875 that the answer relies on running amplify commands with the --restore flag, but this obviously isn't a persistent, source-control-backed change that will survive through CI etc.

How can this environment-specific behvaiour be represented through code?

TL;DR: How can I configure, through commitable code, for cognito auth to have a trigger lambda, but in one amplify environment only

Thanks

@mishabruml mishabruml added pending-triage Issue is pending triage question General question labels Jul 19, 2024
@mishabruml
Copy link
Author

related: #1115

@ykethan
Copy link
Member

ykethan commented Aug 9, 2024

Hey, this is currently not supported on Amplify CLI. But the workaround would be to utilize the ENV environment variable that Amplify deploy on the function by default and separate the config.

export const handler = (event) => {
  if (process.env.ENV) {
    return event
  }
  // your prod env logic
}

Marking as feature request

@ykethan ykethan added feature-request Request a new feature platform-config Issues related to configuring project settings and removed question General question pending-triage Issue is pending triage labels Aug 9, 2024
@mishabruml
Copy link
Author

Thanks for the reply, thats really helpful to know. I ended up at this conclusion and had already implemented pretty much exactly what you suggested. Seems like if this functionality doesn't already exist then its a huge, core-level change so I should not expect anything in the immediate future?

Is there no way to manually modify the underlying cloudformation in order to acheive this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request a new feature platform-config Issues related to configuring project settings
Projects
None yet
Development

No branches or pull requests

2 participants