Skip to content

fix(aws-route53-targets): add support for custom cname_prefix urls in elastic beanstalk environment endpoint target#18804

Merged
mergify[bot] merged 8 commits intoaws:masterfrom
nicfix:aws-route53-elasticbeanstalk-target-urls-fix
Mar 9, 2022
Merged

fix(aws-route53-targets): add support for custom cname_prefix urls in elastic beanstalk environment endpoint target#18804
mergify[bot] merged 8 commits intoaws:masterfrom
nicfix:aws-route53-elasticbeanstalk-target-urls-fix

Conversation

@nicfix
Copy link
Copy Markdown
Contributor

@nicfix nicfix commented Feb 2, 2022

This PR fixes the extraction of the region name from a Elastic Beanstalk Environment URL generated with a custom CNAME_PREFIX.

The code is backward compatible with the regular URL

Motivation

ElasticBeanstalkEnvironmentEndpointTarget is used to create an alias target for ElasticBeanstalk Environments that are already created and published for a certain region.

When creating an ElasticBeanstalk Environment is possible to configure a cname_prefix in order to have a "deterministic" url for the generated environment.

Normally the generated url looks like mybeanstalkenvironment.xyz.eu-west-1.elasticbeanstalk.com, however when the cname_prefix is specified the url loses the randomly generated hash and looks like mycnameprefix.eu-west-1.elasticbeanstalk.com.

In the custom cname_prefix scenario the ElasticBeanstalkEnvironmentEndpointTarget class fails with the following error:

jsii.errors.JSIIError: Elastic Beanstalk environment target is not supported for the "elasticbeanstalk" region.

I mentioned this problem also here, sorry for the double comment. This PR does not fix the original problem of that issue thread.

How to reproduce

Consider this scenario:

# app1.py
# EB Enviroment
enviroment = elasticbeanstalk.CfnEnvironment(self, 'Enviroment', 
    environment_name='MySampleEnviroment',
    application_name=application.application_name or application_name,
    solution_stack_name=SOLUTION_STACK_NAME,
    option_settings=self.get_option_setting_properties(),
    version_label=app_version_props.ref,
    cname_prefix='myapp'
)

This generates an elastic beanstalk environment with url myapp.eu-west-1.elasticbeanstalk.com (supposing one it's deploying in eu-west-1).

Then a following cdk app tries to create a DNS record for it

# app2.py
route53.ARecord(self, f'{construct_label}AliasRecord',
    target=route53.RecordTarget.from_alias(
        targets.ElasticBeanstalkEnvironmentEndpointTarget(     
            'myapp.eu-west-1.elasticbeanstalk.com',
        ),
    ),
    zone=domain_configuration.hosted_zone,
)

At this point the command cdk diff returns the following error:

jsii.errors.JSIIError: Elastic Beanstalk environment target is not supported for the "elasticbeanstalk" region.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…k when configuring the custom_prefix attribute.

Added a test to verify the new urls support.
@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Feb 2, 2022

@nicfix
Copy link
Copy Markdown
Contributor Author

nicfix commented Feb 11, 2022

Hi @comcalvi,

any chance to review this PR?

@comcalvi
Copy link
Copy Markdown
Contributor

@nicfix Thanks for the PR submission! I'll get to this ASAP, no later than next week.

@nicfix
Copy link
Copy Markdown
Contributor Author

nicfix commented Feb 14, 2022

Thanks a lot @comcalvi !

@nicfix
Copy link
Copy Markdown
Contributor Author

nicfix commented Mar 7, 2022

Hi @comcalvi,
did you have some time to check it out?
I am really looking forward to having this problem solved

Copy link
Copy Markdown
Contributor

@comcalvi comcalvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 9, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: fda0c4e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 289a794 into aws:master Mar 9, 2022
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 9, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@bshrram
Copy link
Copy Markdown

bshrram commented Mar 11, 2022

May this PR be merged to cdk v2 too? because it has the same issue

TheRealAmazonKendra pushed a commit to TheRealAmazonKendra/aws-cdk that referenced this pull request Mar 11, 2022
… elastic beanstalk environment endpoint target (aws#18804)

This PR fixes the extraction of the region name from a Elastic Beanstalk Environment URL generated with a custom CNAME_PREFIX.

The code is backward compatible with the regular URL

# Motivation

ElasticBeanstalkEnvironmentEndpointTarget is used to create an alias target for ElasticBeanstalk Environments that are already created and published for a certain region.

When creating an ElasticBeanstalk Environment is possible to configure a `cname_prefix` in order to have a "deterministic" url for the generated environment.

Normally the generated url looks like `mybeanstalkenvironment.xyz.eu-west-1.elasticbeanstalk.com`, however when the `cname_prefix` is specified the url loses the randomly generated hash and looks like `mycnameprefix.eu-west-1.elasticbeanstalk.com`.

In the custom `cname_prefix` scenario the `ElasticBeanstalkEnvironmentEndpointTarget` class fails with the following error:
```
jsii.errors.JSIIError: Elastic Beanstalk environment target is not supported for the "elasticbeanstalk" region.
```

I mentioned this problem also [here](aws#17992 (comment)), sorry for the double comment. This PR does not fix the original problem of that issue thread.

# How to reproduce
Consider this scenario:
```
# app1.py
# EB Enviroment
enviroment = elasticbeanstalk.CfnEnvironment(self, 'Enviroment', 
    environment_name='MySampleEnviroment',
    application_name=application.application_name or application_name,
    solution_stack_name=SOLUTION_STACK_NAME,
    option_settings=self.get_option_setting_properties(),
    version_label=app_version_props.ref,
    cname_prefix='myapp'
)
```

This generates an elastic beanstalk environment with url `myapp.eu-west-1.elasticbeanstalk.com` (supposing one it's deploying in eu-west-1).

Then a following cdk app tries to create a DNS record for it
```
# app2.py
route53.ARecord(self, f'{construct_label}AliasRecord',
    target=route53.RecordTarget.from_alias(
        targets.ElasticBeanstalkEnvironmentEndpointTarget(     
            'myapp.eu-west-1.elasticbeanstalk.com',
        ),
    ),
    zone=domain_configuration.hosted_zone,
)
```

At this point the command cdk diff returns the following error:
```
jsii.errors.JSIIError: Elastic Beanstalk environment target is not supported for the "elasticbeanstalk" region.
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants