image builder distribution LaunchTemplateConfigurations to other region

0

hi could you give me an example of config about image builder distribution LaunchTemplateConfigurations to other region? i always get error: Account "source accoutId" must be provided as a target account in region 'target region' to use launchTemplateConfigurations. here is the config:

Distribution:
    Type: 'AWS::ImageBuilder::DistributionConfiguration'
    Properties:
      Name: 'CUDA 2204 Distribution'
      Description: 'Distribution for CUDA 22.04.'
      Distributions:
        - Region: !Ref 'AWS::Region'     # it works in same region!!!
          AmiDistributionConfiguration:
            Name:
              !Sub 'CUDA2204 - ${GetVersion.version} {{imagebuilder:buildDate}}'
            Description: 'CUDA image based on Ubuntu 22.04'
            AmiTags:
              ImageBuilder: 'CUDA2204'
              Owner: !Ref 'Owner'
              Version: !GetAtt 'GetVersion.version'
            TargetAccountIds:
              - xxxxxxxx   # # AwsNetworkModelsDev01 
          LaunchTemplateConfigurations:
            - AccountId: !Sub '${AWS::AccountId}'
              LaunchTemplateId: '{{resolve:ssm:/LaunchTemplate/CUDA2204/Id}}'
              SetDefaultVersion: true
            - AccountId: xxxxxxxxxx              # (accout id in same region)
              LaunchTemplateId: xxxxxx       #(launchtemplate in target account)
              SetDefaultVersion: true
        - Region: xxxxxxx. (another region)
          AmiDistributionConfiguration:
            Name:
              !Sub 'CUDA2204 - ${GetVersion.version} {{imagebuilder:buildDate}}'
            Description: 'CUDA image based on Ubuntu 22.04'
            AmiTags:
              ImageBuilder: 'CUDA2204'
              Owner: !Ref 'Owner'
              Version: !GetAtt 'GetVersion.version'
            TargetAccountIds:
              - xxxxxxx      # AwsNetworkModelsDev02 
          LaunchTemplateConfigurations
            - AccountId: xxxxxxxxx           #(target account in another region)
              LaunchTemplateId: xxxxxxxx        #(launchtemplate in target account in another region)
              SetDefaultVersion: true
echzhai
asked 5 months ago204 views
1 Answer
0

I was able to replicate a similar error message to yours by using below-mentioned template.

AWSTemplateFormatVersion: 2010-09-09
Description: Testing Distributor
Parameters: 
  TargetAccountId:
    Type: String
Resources:
  Distribution:
    Type: 'AWS::ImageBuilder::DistributionConfiguration'
    Properties:
      Name: Multi Region Distributor
      Description: Multi Region Distributor
      Distributions:
        - Region: us-east-1
          AmiDistributionConfiguration:
            Name: 'AMI-us-east-1 {{ imagebuilder:buildDate }}'
            Description: AMI-us-east-1
            TargetAccountIds:
              - !Ref AWS::AccountId
          LaunchTemplateConfigurations:
            - AccountId: !Ref AWS::AccountId
              LaunchTemplateId: lt-xxxxxxxxxxxxx
              SetDefaultVersion: true
        - Region: us-east-2
          AmiDistributionConfiguration:
            Name: 'AMI-us-east-2 {{ imagebuilder:buildDate }}'
            Description: AMI-us-east-2
            TargetAccountIds:
              - !Ref TargetAccountId
              # - !Ref AWS::AccountId
          LaunchTemplateConfigurations:
            - AccountId: !Ref TargetAccountId
              LaunchTemplateId: lt-xxxxxxxxxxxxx
              SetDefaultVersion: true

In order to resolve the issue, I simply added the source account id in the TargetAccountIds for the us-east-2 region configuration as well and retried the stack creation.

AWSTemplateFormatVersion: 2010-09-09
Description: Testing Distributor
Parameters: 
  TargetAccountId:
    Type: String
Resources:
  Distribution:
    Type: 'AWS::ImageBuilder::DistributionConfiguration'
    Properties:
      Name: Multi Region Distributor
      Description: Multi Region Distributor
      Distributions:
        - Region: us-east-1
          AmiDistributionConfiguration:
            Name: 'AMI-us-east-1 {{ imagebuilder:buildDate }}'
            Description: AMI-us-east-1
            TargetAccountIds:
              - !Ref AWS::AccountId
          LaunchTemplateConfigurations:
            - AccountId: !Ref AWS::AccountId
              LaunchTemplateId: lt-xxxxxxxxxxxxx
              SetDefaultVersion: true
        - Region: us-east-2
          AmiDistributionConfiguration:
            Name: 'AMI-us-east-2 {{ imagebuilder:buildDate }}'
            Description: AMI-us-east-2
            TargetAccountIds:
              - !Ref TargetAccountId
              - !Ref AWS::AccountId
          LaunchTemplateConfigurations:
            - AccountId: !Ref TargetAccountId
              LaunchTemplateId: lt-xxxxxxxxxxxxx
              SetDefaultVersion: true

With this template, I was able to create the stack successfully. Please refer to the above-mentioned template as an example and if needed any troubleshooting on your stack, you can reach out to us by creating a support case from the Support Center.

AWS
SUPPORT ENGINEER
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions