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

Can't use envName in override.ts for API category #12966

Closed
redjonzaci opened this issue Jul 18, 2023 · 6 comments
Closed

Can't use envName in override.ts for API category #12966

redjonzaci opened this issue Jul 18, 2023 · 6 comments
Labels
override Issues related to resource override CDK functionality pending-triage Issue is pending triage

Comments

@redjonzaci
Copy link
Contributor

I paid a little more attention to this comment and I saw that I was trying to use amplifyProjectInfo in an API's override.ts.
Is there any workaround for the API category? Because I can't merge my changes otherwise.

Hey folks in the thread 👋 this is now possible with resource overrides for all categories except for API (for now). You can upgrade to the latest CLI (11.0.3 at the time of writing) and upgrade the Extensibility helper - with CDK v2.

Once upgraded, you can add the second argument to the override function amplifyProjectInfo to get the project name and environment name! 🎉

import {
  AmplifyAuthCognitoStackTemplate,
  AmplifyProjectInfo,
} from '@aws-amplify/cli-extensibility-helper'

export function override(
  resources: AmplifyAuthCognitoStackTemplate,
  amplifyProjectInfo: AmplifyProjectInfo
) {
  console.log(amplifyProjectInfo.projectName, amplifyProjectInfo.envName)
}

Originally posted by @redjonzaci in #9063 (comment)

@redjonzaci
Copy link
Contributor Author

redjonzaci commented Jul 18, 2023

I need to use envName in my API override.ts.

@redjonzaci redjonzaci changed the title Can't use envName in override.ts for API category Can't use envName in override.ts for API category Jul 18, 2023
@redjonzaci
Copy link
Contributor Author

As a workaround, I got the envName by using Fn::Select and Fn::Split on AWS::StackName in addPropertyOverride.

@josefaidt josefaidt added the pending-triage Issue is pending triage label Jul 18, 2023
@josefaidt
Copy link
Contributor

Hey @redjonzaci 👋 thanks for raising this! What was the original issue when attempting to use this property? You should also be able to use the env parameter on the stack.

@josefaidt josefaidt added pending-response Issue is pending response from the issue author override Issues related to resource override CDK functionality labels Jul 18, 2023
@redjonzaci
Copy link
Contributor Author

@josefaidt I wanted to override the OpenSearch domain name to be a specific string + envName, like Lambda function names are for example. As for the env parameter, it gave me an error when trying to access it like "Fn::Sub": "${env}". But the workaround is okay.

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Jul 18, 2023
@josefaidt
Copy link
Contributor

Hey @redjonzaci thanks for clarifying and that sounds good! For what it's worth when you need to reference a CFN stack parameter you will also need to write the CFN block rather than CDK. This is largely different by the property names where CDK is camelCase and CFN is PascalCase.

Given the workaround I will mark this as resolved, but if you encounter this again please do not hesitate to reach back out by filing a bug report!

@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
override Issues related to resource override CDK functionality pending-triage Issue is pending triage
Projects
None yet
Development

No branches or pull requests

2 participants