cloudformation-coverage-roadmap icon indicating copy to clipboard operation
cloudformation-coverage-roadmap copied to clipboard

AWS::Lightsail::Distribution "Resource of type 'Distribution' with identifier already exists."

Open sgargel opened this issue 3 years ago • 1 comments

Name of the resource

AWS::Lightsail::Distribution

Resource Name

AWS::Lightsail::Distribution

Issue Description

Stated that there aren't any Lightsail distribution configured:

image

image

Deploying AWS::Lightsail::Distribution using the template below throws this error:

Resource handler returned message: "Resource of type 'Distribution' with identifier 'distribution-2' already exists."

  WebAppCDN:
    Type: AWS::Lightsail::Distribution
    Properties:
      BundleId: small_1_0
      CacheBehaviors: 
        - 
          Behavior: cache
          Path: _next/static/*

        - 
          Behavior: cache
          Path: _next/image*

                                                          
      CacheBehaviorSettings: 
        AllowedHTTPMethods: GET,HEAD
        CachedHTTPMethods: GET,HEAD
        DefaultTTL: 500
        #ForwardedCookies: 
        #  CookieObject
        #ForwardedHeaders: 
        #  HeaderObject
        #ForwardedQueryStrings: 
        #  QueryStringObject
        MaximumTTL: 1800
        MinimumTTL: 60

      #CertificateName: String
      DefaultCacheBehavior: 
        Behavior: dont-cache
      DistributionName: distribution-2
      #IpAddressType: ipv4
      IsEnabled: true
      Origin: 
        Name: my-webapp-service
        #Region: eu-central-1

Changing DistributionName values does not work.

Expected Behavior

The expected behavior is the ability to deploy the resource.

Observed Behavior

There isn't a DistributionName value that cloudformation accepts and the parameter is mandatory.

Test Cases

Origin my-webapp-service must exists and in my case is a LightSail container service.

AWSTemplateFormatVersion: "2010-09-09"
Description: >
  LightSail CDN



Resources:

  WebAppCDN:
    Type: AWS::Lightsail::Distribution
    Properties:
      BundleId: small_1_0
      CacheBehaviors: 
        - 
          Behavior: cache
          Path: _next/static/*

        - 
          Behavior: cache
          Path: _next/image*
                                                          
      CacheBehaviorSettings: 
        AllowedHTTPMethods: GET,HEAD
        CachedHTTPMethods: GET,HEAD
        DefaultTTL: 500
        #ForwardedCookies: 
        #  CookieObject
        #ForwardedHeaders: 
        #  HeaderObject
        #ForwardedQueryStrings: 
        #  QueryStringObject
        MaximumTTL: 1800
        MinimumTTL: 60

      #CertificateName: String
      DefaultCacheBehavior: 
        Behavior: dont-cache
      DistributionName: distribution-2
      #IpAddressType: ipv4
      IsEnabled: true
      Origin: 
        Name: my-webapp-service
        #Region: eu-central-1

Other Details

No response

sgargel avatar Jun 07 '22 12:06 sgargel

Thanks for reporting this bug! We will be working on a fix for this. In the meantime, a quick workaround would be to create a dummy Lightsail resource in us-east-1 (any type of resource will do) before creating the CloudFormation stack with the distribution. You can delete the dummy resource after the stack is created.

godduv-amzn avatar Jul 11 '22 16:07 godduv-amzn

This issue has been fixed!

godduv-amzn avatar Dec 21 '22 07:12 godduv-amzn