Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

'One or more of the CNAMEs you provided are already associated with a different resource.' #324

Closed
bobrown101 opened this issue Mar 18, 2020 · 10 comments

Comments

@bobrown101
Copy link

Describe the bug
I am deploying a basic next.js application that generates an entire "static" site in terms of next.js.
I had deployed this site multiple times before a few days ago. I came back to do an update and get the following error CNAMEAlreadyExists: One or more of the CNAMEs you provided are already associated with a different resource.

To Reproduce

frontend:
  component: "serverless-next.js"
  inputs:
    domain: "..domain here"
serverless
...site begins to deploy

error:
  CNAMEAlreadyExists: One or more of the CNAMEs you provided are already associated with a different resource.
    at Request.extractError (/Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/protocol/rest_xml.js:53:29)
    at Request.callListeners (/Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/Users/bradybrown/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
  message: 'One or more of the CNAMEs you provided are already associated with a different resource.',
  code: 'CNAMEAlreadyExists',
  time: 2020-03-18T02:08:48.581Z,
  requestId: 'redacted',
  statusCode: 409,
  retryable: false,
  retryDelay: 50.114298601339804
}

  34s › frontend › CNAMEAlreadyExists: One or more of the CNAMEs you provided are already associated with a different resource.

Desktop (please complete the following information):

  • OS: OSX
  • Version: 10.15.3 (19D76)
@bobrown101
Copy link
Author

Here is the debug log

serverless --debug                                        

  DEBUG ─ Resolving the template's static variables.
  DEBUG ─ Collecting components from the template.
  DEBUG ─ Downloading any NPM components found in the template.
  DEBUG ─ Analyzing the template's components dependencies.
  DEBUG ─ Creating the template's components graph.
  DEBUG ─ Syncing template state.
  DEBUG ─ Executing the template's components graph.
  DEBUG ─ Deploying bucket exktrms-21ijq2l in region us-east-1.
  DEBUG ─ Checking if bucket exktrms-21ijq2l exists.
  DEBUG ─ Setting acceleration to "true" for bucket exktrms-21ijq2l.
  DEBUG ─ Bucket exktrms-21ijq2l was successfully deployed to the us-east-1 region.
  DEBUG ─ Starting upload to bucket exktrms-21ijq2l in region us-east-1
  DEBUG ─ Starting upload to bucket exktrms-21ijq2l in region us-east-1
  DEBUG ─ Starting upload to bucket exktrms-21ijq2l in region us-east-1
  DEBUG ─ Starting upload to bucket exktrms-21ijq2l in region us-east-1
  DEBUG ─ Uploading file /Users/bradybrown/Developer/bradybrowninfo/.next/serverless/pages/index.html to bucket exktrms-21ijq2l
  DEBUG ─ Uploading file /Users/bradybrown/Developer/bradybrowninfo/.next/serverless/pages/index.html to bucket exktrms-21ijq2l
  DEBUG ─ Uploading directory /Users/bradybrown/Developer/bradybrowninfo/.next/static to bucket exktrms-21ijq2l
  DEBUG ─ Starting upload to bucket exktrms-21ijq2l in region us-east-1
  DEBUG ─ Uploading file /Users/bradybrown/Developer/bradybrowninfo/.next/serverless/pages/404.html to bucket exktrms-21ijq2l
  DEBUG ─ Uploading directory /Users/bradybrown/Developer/bradybrowninfo/public to bucket exktrms-21ijq2l
  DEBUG ─ File /Users/bradybrown/Developer/bradybrowninfo/.next/serverless/pages/404.html uploaded with key static-pages/404.html
  DEBUG ─ File /Users/bradybrown/Developer/bradybrowninfo/.next/serverless/pages/index.html uploaded with key static-pages/index.html
  DEBUG ─ File /Users/bradybrown/Developer/bradybrowninfo/.next/serverless/pages/index.html uploaded with key static-pages/index.html
  DEBUG ─ Starting deployment of lambda exktrms-oqh8qv to the us-east-1 region.
  DEBUG ─ Syncing role exktrms-e8kq28d in region us-east-1.
  DEBUG ─ Saved state for role exktrms-e8kq28d.
  DEBUG ─ Role exktrms-e8kq28d was successfully deployed to region us-east-1.
  DEBUG ─ Deployed role arn is arn:aws:iam::052969257673:role/exktrms-e8kq28d.
  DEBUG ─ Packaging lambda code from /Users/bradybrown/Developer/bradybrowninfo/.serverless_nextjs/default-lambda.
  DEBUG ─ Uploading exktrms-oqh8qv lambda code.
  DEBUG ─ Updating exktrms-oqh8qv lambda config.
  DEBUG ─ Successfully deployed lambda exktrms-oqh8qv in the us-east-1 region.
  DEBUG ─ Starting deployment of CloudFront distribution to the us-east-1 region.
  DEBUG ─ Updating CloudFront distribution of ID E6RQD4GKD4ZLU.
  DEBUG ─ CloudFront deployed successfully with URL: https://d3r6s6rf1kuqun.cloudfront.net.
  DEBUG ─ Starting Domain component deployment.
  DEBUG ─ Validating inputs.
  DEBUG ─ Formatting domains and identifying cloud services being used.
  DEBUG ─ Getting the Hosted Zone ID for the domain bradybrown.info.
  DEBUG ─ Searching for an AWS ACM Certificate based on the domain: bradybrown.info.
  DEBUG ─ Checking the status of AWS ACM Certificate.
  DEBUG ─ Adding www.bradybrown.info domain to CloudFront distribution with URL "https://d3r6s6rf1kuqun.cloudfront.net"

  error:
  CNAMEAlreadyExists: One or more of the CNAMEs you provided are already associated with a different resource.

@bobrown101
Copy link
Author

Im adding this here as documentation for anyone else who runs into this issue. I resolved this by performing the following (note - I am not sure what part/s of the following steps actually fixed the problem, but what I did below fixed it and thats the important thing)

rm -rf .next
rm -rf .serverless
rm -rf .serverless_nextjs
rm -rf node_modules

Go to AWS Cloudfront console
remove all distributions associated with your domain

serverless # should now work

@jolosimeon
Copy link

jolosimeon commented Mar 18, 2020

Experience this a lot when deploying from different machines. I was looking in to setting up CI/CD for my Next.js project but it looks like this will be an issue if deploying builds on different machines/instances does not work

@krzysztof-miemiec
Copy link

krzysztof-miemiec commented Mar 27, 2020

@jolosimeon maybe this will help: #328 (comment)

I noted two options in linked comment:

  • ditch Serverless components in favor of Terraform (I went this way, as I already have some experience in it)
  • Use S3 bucket & AWS CLI to sync state with local machine (that's actually similar to how Terraform works internally).

@hnprashanth
Copy link

This problem occurs because as of today this component doesn't reliably detect if the deployment already has the resource. So after a few deploys, it tries to create a new CF distribution and tries to attach the domain & fails since it is already attached to the older deployment! I'm struggling this issue for some time now and tried many workarounds but nothing is reliable.

@plorencrstit
Copy link

I have the same problem. It is a blocker when the plugin can not detect if the deployment (domain) already has been set.

@medv
Copy link

medv commented Jul 21, 2020

This issue is documented in the readme - you need to make sure you keep your .serverless folder between deploys. If you are using multiple machines then set up a simple CI/CD process triggered by a merged pull request that syncs it from and back to an S3 bucket and do not deploy from your machine.

@plorencrstit
Copy link

plorencrstit commented Jul 21, 2020

This issue is documented in the readme - you need to make sure you keep your .serverless folder between deploys. If you are using multiple machines then set up a simple CI/CD process triggered by a merged pull request that syncs it from and back to an S3 bucket and do not deploy from your machine.

Ok. I don't want to have .serverless. in repository. As I understand I can use this example: https://gist.github.com/hadynz/b4e190e0ce10e5811cb462920a9c678f

How about this PR: #477
When can it be merged?

Gist
Serverless deploy with state management in S3. GitHub Gist: instantly share code, notes, and snippets.

@medv
Copy link

medv commented Jul 23, 2020

Yes that's correct. I don't think that PR will bypass the requirement for keeping state as there are other resources created during the deployment of this component, not just CloudFront.

@dphang
Copy link
Collaborator

dphang commented Oct 11, 2020

I've documented the .serverless sync solution here and the PR mentioned above is already available, so assuming this can be closed. Let us know if there are any other related issues. Thanks!

@dphang dphang closed this as completed Oct 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants