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-imagebuilder): "The value supplied for parameter 'distributions[0]' is not valid" deploying a distribution configuration #12882

Closed
roebius opened this issue Feb 5, 2021 · 10 comments
Assignees
Labels
@aws-cdk/aws-imagebuilder Related to EC2 Image Builder bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@roebius
Copy link

roebius commented Feb 5, 2021

I have an EC2 Image Builder image pipeline stack that works fine when I deploy it without a distribution configuration.
When I add a distribution configuration the stack deployment fails during the distribution step.

Reproduction Steps

The following simplified stack, extracted from my complete pipeline stack, is reproducing the same issue:

#!/usr/bin/env python3

from aws_cdk import core, aws_imagebuilder as imagebuilder


class DistrConfigStack(core.Stack):

    def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Image distribution configuration 
        distrconfig = imagebuilder.CfnDistributionConfiguration(
            self,
            'DistrConfig',
            name='DistrConfigTest',
            distributions=[
                imagebuilder.CfnDistributionConfiguration.DistributionProperty(region='eu-west-1'),
                imagebuilder.CfnDistributionConfiguration.DistributionProperty(region='eu-central-1')
            ]
        )

        # Outputs
        core.CfnOutput(self, 'DistrConfigCfnOutput0', value=distrconfig.distributions[0].region)
        core.CfnOutput(self, 'DistrConfigCfnOutput1', value=distrconfig.distributions[1].region)


app = core.App()
config_ami = DistrConfigStack(app, "Distrconfig", env=core.Environment(region='eu-west-1'))
app.synth()

What did you expect to happen?

My goal is to deploy an Image Builder pipeline stack that includes distribution of the EC2 image to a number of AWS regions.

What actually happened?

When I add the distribution configuration in my pipeline stack, however, the deployment fails.

When the stack deployment fails the following error is shown:

The value supplied for parameter 'distributions[0]' is not valid. One or more outputs should be provided for each region in a distribution configuration. (Service: Imagebuilder, Status Code: 400, Request ID: 7d5036b5-e982-476b-9694-5eab88737efe, Extended Request ID: null)

Environment

  • CDK CLI Version : 1.88.0 (and same version also for all the Python CDK packages)
  • Framework Version:
  • Node.js Version: v10.19.0
  • OS : Ubuntu 20.04
  • Language (Version): Python (3.8.5)

Other

In case it helps, this is the output of cdk synth:

Resources:
  DistrConfig:
    Type: AWS::ImageBuilder::DistributionConfiguration
    Properties:
      Distributions:
        - Region: eu-west-1
        - Region: eu-central-1
      Name: DistrConfigTest
    Metadata:
      aws:cdk:path: Distrconfig/DistrConfig
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Modules: aws-cdk=1.88.0,@aws-cdk/aws-imagebuilder=1.88.0,@aws-cdk/cloud-assembly-schema=1.88.0,@aws-cdk/core=1.88.0,@aws-cdk/cx-api=1.88.0,@aws-cdk/region-info=1.88.0,jsii-runtime=Python/3.8.5
    Metadata:
      aws:cdk:path: Distrconfig/CDKMetadata/Default
Outputs:
  DistrConfigCfnOutput0:
    Value: eu-west-1
  DistrConfigCfnOutput1:
    Value: eu-central-1

For CDK Image Builder I could not find any examples of image pipeline stacks including distributions: it would definitely help seeing one.


This is 🐛 Bug Report

@roebius roebius added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 5, 2021
@github-actions github-actions bot added the @aws-cdk/aws-imagebuilder Related to EC2 Image Builder label Feb 5, 2021
@skinny85
Copy link
Contributor

skinny85 commented Feb 5, 2021

@roebius thanks for reporting.

Can you try a simple experiment for me? Can you try passing a list of strings for the distributions property, instead of a list of CfnDistributionConfiguration.DistributionProperty objects? You can do it using escape hatches. For an example, see this comment.

Thanks,
Adam

@skinny85 skinny85 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 5, 2021
@roebius
Copy link
Author

roebius commented Feb 5, 2021

After checking the docs about escape hatches I tried to modify my code inserting overrides, but it didn't work.
Here is the code:

#!/usr/bin/env python3

from aws_cdk import core, aws_imagebuilder as imagebuilder


class DistrConfigStack(core.Stack):

    def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Image distribution configuration
        distrconfig = imagebuilder.CfnDistributionConfiguration(
            self,
            'DistrConfig',
            name='DistrConfigTest',
            distributions=[
                imagebuilder.CfnDistributionConfiguration.DistributionProperty(region='eu-west-1'),
                imagebuilder.CfnDistributionConfiguration.DistributionProperty(region='eu-central-1')
            ]
        )

        distrconfig.add_deletion_override('DistributionProperty.0.region')
        distrconfig.add_deletion_override('DistributionProperty.1.region')
        distrconfig.add_override('DistributionProperty.0.region', 'eu-west-1')
        distrconfig.add_override('DistributionProperty.1.region', 'eu-central-1')

        # Outputs
        core.CfnOutput(self, 'DistrConfigCfnOutput0', value=distrconfig.distributions[0].region)
        core.CfnOutput(self, 'DistrConfigCfnOutput1', value=distrconfig.distributions[1].region)


app = core.App()
config_ami = DistrConfigStack(app, "Distrconfig", env=core.Environment(region='eu-west-1'))
app.synth()

And here is the result:

$ cdk synth
Resources:
  DistrConfig:
    Type: AWS::ImageBuilder::DistributionConfiguration
    Properties:
      Distributions:
        - Region: eu-west-1
        - Region: eu-central-1
      Name: DistrConfigTest
    Metadata:
      aws:cdk:path: Distrconfig/DistrConfig
    DistributionProperty:
      "0":
        region: eu-west-1
      "1":
        region: eu-central-1
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Modules: aws-cdk=1.88.0,@aws-cdk/aws-imagebuilder=1.88.0,@aws-cdk/cloud-assembly-schema=1.88.0,@aws-cdk/core=1.88.0,@aws-cdk/cx-api=1.88.0,@aws-cdk/region-info=1.88.0,jsii-runtime=Python/3.8.5
    Metadata:
      aws:cdk:path: Distrconfig/CDKMetadata/Default
Outputs:
  DistrConfigCfnOutput0:
    Value: eu-west-1
  DistrConfigCfnOutput1:
    Value: eu-central-1


$ cdk deploy
Distrconfig: deploying...
Distrconfig: creating CloudFormation changeset...

 ❌  Distrconfig failed: ValidationError: Invalid template resource property 'DistributionProperty'
Invalid template resource property 'DistributionProperty'

I also tried to instantiate the distribution configuration by directly passing:
distributions=[{'region': 'eu-west-1'}, {'region': 'eu-central-1'}]
but this gave me the initial error The value supplied for parameter 'distributions[0]' is not valid. ...

Let me know if you had in mind a different way to use the escape hatches. Thx.

@skinny85
Copy link
Contributor

skinny85 commented Feb 6, 2021

Can you try this?

#!/usr/bin/env python3

from aws_cdk import core, aws_imagebuilder as imagebuilder


class DistrConfigStack(core.Stack):

    def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Image distribution configuration
        dist_rconfig = imagebuilder.CfnDistributionConfiguration(
            self, 'DistrConfig',
            name='DistrConfigTest',
            distributions=[],
        )
        dist_rconfig.add_property_override('Distributions', ['eu-west-1', 'eu-central-1'])


app = core.App()
config_ami = DistrConfigStack(app, "Distrconfig", env=core.Environment(region='eu-west-1'))
app.synth()

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 6, 2021
@roebius
Copy link
Author

roebius commented Feb 7, 2021

Did not work: here are the results from cdk synth and cdk deploy:

$ cdk synth
Resources:
  DistrConfig:
    Type: AWS::ImageBuilder::DistributionConfiguration
    Properties:
      Distributions:
        - eu-west-1
        - eu-central-1
      Name: DistrConfigTest
    Metadata:
      aws:cdk:path: Distrconfig/DistrConfig
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Modules: aws-cdk=1.88.0,@aws-cdk/aws-imagebuilder=1.88.0,@aws-cdk/cloud-assembly-schema=1.88.0,@aws-cdk/core=1.88.0,@aws-cdk/cx-api=1.88.0,@aws-cdk/region-info=1.88.0,jsii-runtime=Python/3.8.5
    Metadata:
      aws:cdk:path: Distrconfig/CDKMetadata/Default

$ cdk deploy
Distrconfig: deploying...
Distrconfig: creating CloudFormation changeset...
[███████████████████▎······································] (1/3)

8:43:43 AM | CREATE_FAILED        | AWS::ImageBuilder::DistributionConfiguration | DistrConfig
Model validation failed (#/Distributions/0: expected type: JSONObject, found: String
#/Distributions/1: expected type: JSONObject, found: String)
8:43:44 AM | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack                   | Distrconfig
The following resource(s) failed to create: [DistrConfig]. Rollback requested by user.
8:43:44 AM | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack                   | Distrconfig
The following resource(s) failed to create: [DistrConfig]. Rollback requested by user.

Seeing the error expected type: JSONObject I looked at the CloudFormation format specifications here and here, then tried

dist_rconfig.add_property_override('Distributions', [{"Region": "eu-west-1"}, {"Region": "eu-central-1"}])
which still gives the initial error.

I tried several other variations. The only one completing cdk deploy without errors was this:

dist_rconfig.add_property_override('Distributions', {'Distributions': [{"Region": "eu-west-1"}, {"Region": "eu-central-1"}]})

but then in the resulting distribution configuration the distributions parameter is an empty list (seen with cdk synth, Image Builder console or Boto3 script).

@skinny85
Copy link
Contributor

skinny85 commented Feb 8, 2021

So it seems like this:

    Type: AWS::ImageBuilder::DistributionConfiguration
    Properties:
      Distributions:
        - Region: eu-west-1
        - Region: eu-central-1

is the correct shape for that property, and that

        imagebuilder.CfnDistributionConfiguration(
            self,
            'DistrConfig',
            name='DistrConfigTest',
            distributions=[
                imagebuilder.CfnDistributionConfiguration.DistributionProperty(region='eu-west-1'),
                imagebuilder.CfnDistributionConfiguration.DistributionProperty(region='eu-central-1')
            ]
        )

is the correct code...

In this case, I'm pretty stumped 😕. This doesn't seem to be a CDK issue... Do you have premium support @roebius ? Can you open an issue to the team that owns ImageBuilder?

@skinny85 skinny85 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 8, 2021
@roebius
Copy link
Author

roebius commented Feb 8, 2021

It seems this works:

#!/usr/bin/env python3
from aws_cdk import core, aws_imagebuilder as imagebuilder


class DistrConfigStack(core.Stack):

    def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Image distribution configuration
        dist_rconfig = imagebuilder.CfnDistributionConfiguration(
            self, 'DistrConfig',
            name='DistrConfigTest',
            distributions=[],
        )
        dist_rconfig.add_property_override(
            'Distributions',
            [
               {
                   'Region': 'eu-west-1',                                                        # mandatory
                   'AmiDistributionConfiguration': {'Name': 'MyAmi {{imagebuilder:buildDate}}'}  # optional
                },
               {
                   'Region': 'eu-central-1',                                                     # mandatory
                   'AmiDistributionConfiguration': {'Name': 'MyAmi {{imagebuilder:buildDate}}'}  # optional
               }
            ])


app = core.App()
config_ami = DistrConfigStack(app, "Distrconfig", env=core.Environment(region='eu-west-1'))
app.synth()

This is the same as the override that still gives the initial error
dist_rconfig.add_property_override('Distributions', [{"Region": "eu-west-1"}, {"Region": "eu-central-1"}])

but for each list element (a distribution) I added one of the optional parameters (I picked AmiDistributionConfiguration specifying just Name, didn't have time to test other options).

This successfully deploys the distribution configuration. If I comment out the optional parameters the initial error shows up.

As you indicate, this seems to be the corrrect code, at least when adding ami_distribution_configuration:

        imagebuilder.CfnDistributionConfiguration(
            self, 
            'DistrConfig',
            name='DistrConfigTest',
            distributions=[
                imagebuilder.CfnDistributionConfiguration.DistributionProperty(
                    region='eu-west-1',
                    ami_distribution_configuration={'Name': 'MyAmi {{imagebuilder:buildDate}}'}
                ),
                imagebuilder.CfnDistributionConfiguration.DistributionProperty(
                    region='eu-central-1',
                    ami_distribution_configuration={'Name': 'MyAmi {{imagebuilder:buildDate}}'}
                )
            ]
        )

I do not have premium support so I guess I cannot open a case for this, but let me know.
Thanks

@skinny85
Copy link
Contributor

skinny85 commented Feb 8, 2021

Huh 🤔. Then maybe AmiDistributionConfiguration is actually required, but it's not marked correctly as such in the model...?

Anyhow, glad you got yourself unblocked! Anything else we can help you with on this issue?

@roebius
Copy link
Author

roebius commented Feb 8, 2021

it's not marked correctly as such in the model...?

I think that could be the case, anyway at the moment the issue for me is solved and I do not need additional support.
Again, thanks for your help.

@skinny85 skinny85 closed this as completed Feb 8, 2021
@github-actions
Copy link

github-actions bot commented Feb 8, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or 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.

@BwL1289
Copy link

BwL1289 commented Jan 5, 2024

Related: 26912

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-imagebuilder Related to EC2 Image Builder bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants