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

aws_appconfig, cdk.Fn.import_value: Error: Missing required parameters for environment ARN: format should be /$/{applicationId}/environment//$/{environmentId} #31580

Open
1 task
vivekrpatel8 opened this issue Sep 26, 2024 · 9 comments
Labels
@aws-cdk/aws-appconfig Related to AWS AppConfig @aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@vivekrpatel8
Copy link

Describe the bug

I am creating environment for my AWS App Config using

environment = app.add_environement(id, environment_name)
cdk.CfnOutput(self, "EnvArn", export_name="EnvArn", value=environment.environment_arn)

I am using static method which returns the environment using ARN:

env_arn = cdk.Fn.import_value("EnvArn")
env = Environment.from_environment_arn(scope, construct_id, environment_arn = env_arn)

but getting following error:
@jsii/kernel.RuntimeError: Error: Missing required parameters for environment ARN: format should be /$/{applicationId}/environment//$/{environmentId}

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

It should return environment

Current Behavior

It is throwing error as mentioned

Reproduction Steps

Create environment and try to import it as mentioned in the description

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.154.1

Framework Version

No response

Node.js Version

20.0.0

OS

Windows

Language

Python

Language Version

No response

Other information

No response

@vivekrpatel8 vivekrpatel8 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 26, 2024
@github-actions github-actions bot added the @aws-cdk/aws-appconfig Related to AWS AppConfig label Sep 26, 2024
@khushail khushail self-assigned this Sep 26, 2024
@khushail khushail added needs-reproduction This issue needs reproduction. p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 26, 2024
@khushail
Copy link
Contributor

Hi @vivekrpatel8 , thanks for reaching out.

Not really clear of at which code you are getting the error but AFAIU, here is an AWS Doc which lists out the requirements for Fn:Import.

Looks like you are implementing this as cross-stack reference, I tried to print the arn in first stack just to confirm what is the output value being printed which should be -/$/{applicationId}/environment//$/{environmentId}

Screenshot 2024-09-26 at 5 13 19 PM

Could you please see if the first CfnOutput value corresponds to the format before import.
Also please share the complete code to repro the issue.
Thanks.

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-reproduction This issue needs reproduction. labels Sep 27, 2024
@vivekrpatel8
Copy link
Author

vivekrpatel8 commented Sep 27, 2024

@khushail Yeah exactly lets say I have two stacks... One stack is responsible for provisioning the infra for AppConfig such as creating application and environments. Other stack is a CodePipeline which adds and deploys HostedConfiguration for given app and environment. I tried to run cdk diff, but the output I get is not complete ARN but rather the components of ARN

{"Value":{"Fn::Join":["",["arn:aws:appconfig:us-west-1:random_numbers:application/",{"Ref":"App_ID"}]]},"Export":{"Name":"AppConfigAppArn"}}

@vivekrpatel8
Copy link
Author

@khushail My code looks something like this:

class AppConfigExample(construct):
    def __init__(self, scope: Construct, construct_id: str, **kwargs):
        super().__init__(scope, construct_id, **kwargs)

        app = self.create_app()

        # Consider env_config as a list of objects with name attribute such as [{'name': 'example-env-1'}, {'name': 'example-env-2'}]
        for env in env_config:
            environment = self._create_environment(app=app, env=env)
    
    def create_app(self) -> Application:
        app = Application(self, "AppConfig", application_name="AppConfigExample")
        cdk.CfnOutput(self, "ExampleAppArn", export_name="ExampleAppArn", value=app.application_arn)
        return app

    def _create_environment(self, app: Application, env: dict) -> IEnvironment:
        environment = app.add_environment(f"{env.name}-AppConfigExampleEnv", environment_name=env.name)
        cdk.CfnOutput(self, f"{env.name}ExampleEnvArn", export_name=f"{env.name}ExampleEnvArn", value=environment.environment_arn)
        return environment
    
    @staticmethod
    def import_app_config_app(scope: Construct, construct_id: str) -> IApplication:
        app_arn = cdk.Fn.import_value("ExampleAppArn")
        return Application.from_application_arn(scope, construct_id, application_arn=app_arn)

    @staticmethod
    def import_app_config_env(scope: Construct, construct_id: str, env_name: str) -> IEnvironment:
        env_arn = cdk.Fn.import_value(f"{env_name}ExampleEnvArn")
        return Environment.from_environment_arn(scope, construct_id, environment_arn=env_arn)
    
class SomeOtherStack(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        app = AppConfigExample.import_app_config_app(self, "AppConfigExample")

        for env in env_config:
            environment = AppConfigExample.import_app_config_env(self, f"{env.name}AppConfigExampleEnv", env_name=env.name)
            app.add_hosted_configuration(
                f"{env.name}-HostedConfig",
                name=f"{env.name}-ExampleHostedConfig",
                deploy_to=[environment],
                type=ConfigurationType.FREEFORM,
                content=ConfigurationContent.from_file(file_name)
            )

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 27, 2024
@khushail khushail added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Sep 27, 2024
@khushail
Copy link
Contributor

khushail commented Sep 30, 2024

Hi @vivekrpatel8 , thanks for sharing the code.

I used my above exported value in another stack and got the same error -
Screenshot 2024-09-30 at 2 51 44 PM

AFAIU, this code here is checking the Arn during fromEnvironmentArn()-

public static fromEnvironmentArn(scope: Construct, id: string, environmentArn: string): IEnvironment {

which is invoking this code to check the resource name being imported -

SLASH_RESOURCE_NAME = 'arn:aws:service:region:account:resource/resourceName',

https://github.com/aws/aws-cdk/blob/b0e4a544aecce86e8b41e7cd148a139c2e34bfbd/packages/aws-cdk-lib/aws-appconfig/lib/environment.ts#L190C1-L194C3

  public static fromEnvironmentArn(scope: Construct, id: string, environmentArn: string): IEnvironment {
    const parsedArn = Stack.of(scope).splitArn(environmentArn, ArnFormat.SLASH_RESOURCE_NAME);
    if (!parsedArn.resourceName) {
      throw new Error(`Missing required /$/{applicationId}/environment//$/{environmentId} from environment ARN: ${parsedArn.resourceName}`);
  

Looks like the condition is triggering invocation of printed error message. let me investigate more and get back to you.

@khushail khushail added effort/small Small work item – less than a day of effort investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Sep 30, 2024
@vivekrpatel8
Copy link
Author

vivekrpatel8 commented Oct 1, 2024

Hello @khushail! Thanks for looking into it. I tried to mimic this ARN split logic in my python code and I believe the below code block is the throwing the mentioned error:

image

I think the split logic is incorrect... So instead of using ArnFormat.SLASH_RESOURCE_NAME for retrieving the parsed ARN I tried using other options as well such as ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME, COLON_RESOURCE_NAME, etc. but no luck! It still returns same error and when I split parsed ARN using resource_name = parsed_arn.resource_name.split('/') it always returns list with single value. But code tries to access index 2 for getting Environment ID which end up throwing IndexError: list index out of range error. Or it is also possible that incorrect ARN format is returned by environment.environment_arn.

@khushail
Copy link
Contributor

khushail commented Oct 1, 2024

@vivekrpatel8 , yes you seem to be correct in identifying the block code..

i double checked the generated Synth template to see what is the output of the arn value -

In the first stack , the output is -

"Outputs": {
  "EnvArn": {
   "Value": {
    "Fn::Join": [
     "",
     [
      "arn:aws:appconfig:us-east-1:123456789012:application/",
      {
       "Ref": "MyApp3CE31C26"
      },
      "/environment/",
      {
       "Ref": "Environment78414C64"
      }
     ]
    ]
   },
   "Export": {
    "Name": "EnvArn"
   }
  }

Since the 2nd stack which is importing this , is not getting synthesized, i am not sure how we could check into that imported value. So looks like, the error lies in the fromEnvironmentArn() function itself.

@khushail
Copy link
Contributor

khushail commented Oct 8, 2024

Marking this as P2 as it won't be immediately addressed by the team but would be on their radar.

I will bring this up to the team for their input if this is something we are actively investigating and share our thoughts here if possible.

@khushail khushail added @aws-cdk/core Related to core CDK functionality and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Oct 8, 2024
@khushail khushail removed their assignment Oct 8, 2024
@jiayiwang7 jiayiwang7 self-assigned this Oct 9, 2024
@vivekrpatel8
Copy link
Author

Thanks for the update @khushail

@khushail
Copy link
Contributor

Requesting Core team's input on this issue as this is something being already addressed by the team or share insights on the debugging of issue.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-appconfig Related to AWS AppConfig @aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

No branches or pull requests

3 participants