A few months ago I played around with AWS CDK and so I of course did the cdk bootstrap.
At that time I stopped playing around and thought I'd never use it again. Having a kind of neatly attitude in this kind of things (and missing an undo or delete option being delivered with the cdk itself :/ ) I deleted all cdk objects from my account.
Or at least I thought so, because now (starting to play around again), calling cdk bootstrap does "nothing":
✅ Environment aws://xxxxxxxxx/eu-central-1 bootstrapped (no changes).
But trying to cdk deploy gives me:
fail: No bucket named 'cdk-XXXXXXXXXXX-eu-central-1'. Is account XXXXXXXXXXXX bootstrapped?
Well yes right...I don't have any buckets at all at the moment.
Is there a way to cdk bootstrap --force that I'am missing? Is there a list of all objects I should have deleted? I find a lot suggestions for people having problems with their stacks, but I have no idea how to fix this.
Edit: I just "solved" the problem, by creating a bucket with the given cryptic name...but that doesn't feel right. So I leave this Question open, to see if there is a better way to do it.
Bootstrapping creates a Stack called CDKToolkit, which has the CloudFormation resources CDK needs to deploy. You can safely "uninstall-reinstall" it:
aws cloudformation delete-stack --stack-name CDKToolkit
cdk bootstrap
Note: "Drift" is the technical term for your problem. The actual AWS resource state "drifted" from the expected state defined in the CDKToolkit CloudFormation template. CloudFormation has tools to deal with the drift problem. You can report on drift, for instance:
aws cloudformation detect-stack-drift --stack-name CDKToolkit
Related
I did some clean up in my S3 buckets and deleted S3 bucket with weird names. Now my CDK stacks are in weird states.
I have some CDK stacks running.
$cdk ls shows
LambdaHoroscrape
I destroy the stack with those commands
cdk destroy
cdk destroy LambdaHoroscrape
Are you sure you want to delete: LambdaHoroscrape (y/n)? y
LambdaHoroscrape: destroying...
LambdaHoroscrape: destroyed
However the stack LambdaHoroscrape is still present, cdk ls confirms it.
How can I properly delete this CDK stack ?
Context: I wanted to delete the stack because my deployment ( cdk deploy ) showed this cryptic message
[%] fail: No bucket named 'cdktoolkit-stagingbucket-zd83596pa2cm'. Is account xxxxx bootstrapped?
I boostrapped my account with
cdk bootstrap aws://{account_number}/{region}
Others encountered this cryptic error as well
https://github.com/aws/aws-cdk/issues/6808
In the end, because of this error and eagerness to destroy the stack, I lost my DynamoDB data collected since 2 weeks.
The message is caused by the fact that you deleted the CDK asset bucket created during bootstrapping. You'll need to re-bootstrap your environment to deploy there.
As for deleting, CDK deploys cloudformation stacks, so a sure way to delete something is to go to the cloudformation console and delete the stack.
I'm trying to get this repo going here - https://github.com/mydatastack/google-analytics-to-s3.
A link is provided to launch the AWS CloudFormation stack but it is no longer working as the S3 bucket containing the template is no longer active.
I have 2 questions about getting data pipeline running:
My first question would be what is 631216aef6ab2824fc63572d1d3d5e6c.template and can I create it through the 3 .yml files in the CloudFormation folder?
I've tried to create a template through CloudFormation designer , collector-ga.yml but it fails. I think its because the Resources within the yml aren't available when creating a template just from collector-ga. I've also tried uploading the repo to s3 and creating a template from there but that was also unsuccessful.
How can I launch the stack from the repo? I've found very little information online so an explanation or a pointer to some relevant resources would be appreciated.
This repository doesn't use the "standard" CloudFormation resources, but it uses AWS SAM. You'll have to install the SAM CLI tool and use that to deploy the CloudFormation stack. If you run sam deploy --guided it will help you with the setup of the necessary S3 bucket etc on your AWS account. SAM will upload the necessary files, resolve the internal local links between the templates by updating them with the S3 URLs and construct a packaged.yml template which it will use to deploy the stack.
Also, check out the AWS SAM user guide for more information.
I was testing the AWS SAM functionality and encountered an issue.
If by manually delete a resource that was originally created by the SAM template, then subsequent SAM deployment will fail. I do understand that deleting resource manually that was created by SAM is not a good practice. But this was just a test only
Error
Is there any way to fix this?
AWS SAM uses Cloudformation underneath to create various resources.
How do I update an AWS CloudFormation stack that's failing because of a resource that I manually deleted?
If you delete a resource from an AWS CloudFormation stack, then you must remove the resource from your AWS CloudFormation template. Otherwise, your stack fails to update, and you get an error message.
similar post : Function not found after manually deleting a function in a SAM CloudFormation stack
I can deploy an EB environment via CloudFormation with AWS::ElasticBeanstalk::Environment and AWS::ElasticBeanstalk::ApplicationVersion in the same template
That's great but if the beanstalk app deployment fails CloudFormation doesn't fail- the stack/environment is usually created successfully. So CloudFormation deploys successfully, the Beanstalk app version deploy fails, Beanstalk rolls back to the previous version, and returns to a healthy state and the only way I know it failed is to view the console or doing something wonky like try to check the current app version after the deployment.
The nested stack AWS::ElasticBeanstalk::Environment creates however does seem to fail if the app version deployment fails, but I can find no way of linking the two which is very annoying.
I need to programmatically identify the nested stack AWS::ElasticBeanstalk::Environment creates so after CloudFormation finishes and can check the status of that nested stack to see if the Beanstalk deploy was actually successful
Edit
At least they are tagged with the environment name. I really don't love this but it seems to work, curious about better options though:
aws cloudformation describe-stacks --query 'Stacks[?Tags[?Key == `elasticbeanstalk:environment-name` && Value == `myenvname`]].{StackName: StackName}' --output text
Its technically not a nested stack, but a fully independent stack from AWS::ElasticBeanstalk::Environment.
Nevertheless, one way to get the stack name, would be through custom resource in CFN.
In the CFN you would have a lambda which would use describe-environments using your environment, get the EB stack name, and return it to your stack for further processing.
One of the outcomes of the query is EnvironmentId. For example
"EnvironmentId": "e-ctpmqpqwjm"
The stack that EB produces has name in the format:
awseb-<EnvironmentId>-stack
Sadly, I can't find any reference for this. This is based on my own observations. Thus, if you would choose to explore this option, you would have to verify if the naming convention is same for you.
I have a stack which creates IAM policies
Its deployed successfully
I then change a policy by removing few statements
Then invoke cdk diff, which does not detect the drift
Is this expected?
Indeed, cdk diff will only compare the specified stack with the local template file (created by the previous cdk deploy).
Thus, if you made some changes in the AWS Console, the AWS CDK will not detect the drift.
Since version 1.17.0, you can now do the following to detect and show drifted changes:
cdk deploy --no-execute
From the PR description:
You will be able to see the ChangeSet in AWS CloudFormation Console, validate the resources and discard or execute the ChangeSet.