Does AWS CDK create default stack name in CloudFormation? - aws-cloudformation

Using CloudFormation template, CloudFormation service ask for a stack name(AWS::StackName) before applying the template.
Using AWS CDK, we run cdk synth to create cfn template & cdk deploy to deploy services based on the template.
Does AWS CDK create default stack name in Cloudformation service? after running cdk deploy

In order to create a stack you have to instantiate an object for that stack. When you do, you pass the stack name as a parameter. Example in Python:
class MyStackClass:
(...)
# You have to have an app
app = core.App()
# Here's the stack
MyStack = MyStackClass(app, "StackName")
Other than that, see the docs:
The physical names of the AWS CloudFormation stacks are automatically determined by the AWS CDK based on the stack's construct path in the tree. By default, a stack's name is derived from the construct ID of the Stack object, but you can specify an explicit name using the stackName prop, as follows.
new MyStack(this, 'not:a:stack:name', { stackName: 'this-is-stack-name' });

Related

AWS ECS Blue Green Deployments - CloudFormation Error

Trying to execute a blue/green deployment of an ECS task within AWS using the CloudFormation approach (as documented here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green.html) and the deployment fails.
The initial stack deployment works fine and the ECS task is deployed and running as expected with the correct load balancer and target group etc. However when updating the task definition, to trigger a blue/green deployment, it fails with the message:
Imports and exports are currently not supported on templates using hooks
The deployment is created in CodeDeploy, so it's obviously triggered as expected, but the deployment screen in AWS console shows the following error:
The deployment failed because the stack update that triggered this CodeDeploy deployment failed in CloudFormation. In the AWS CloudFormation console, go to the Events tab to view status and error messages.
But the puzzling thing is the CloudFormation template does not appear to contain any imports or exports. I have even tried copying the yml from the documented example and it doesn't work.
I'm executing the CloudFormation updates using Serverless Framework, but I don't think that's an issue, the error is logged in the CloudFormation stack events tab.
Probably not unreasonable to expect the example in the AWS documentation to work?
So we did find the cause of this issue, and in fact the problem was actually caused by running the CloudFormation template via the serverless framework.
The serverless approach works for all our other AWS deployments, but the CodeDeploy transform explicitly requires for there to be no outputs from the CF template - however serverless actually adds the name of the S3 bucket that it uses as an output, which breaks this particular use case.
Therefore the solution was to invoke the CF template directly from the AWS CLI and it works perfectly.

Find out deployment type of existing ECS service

The AWS doc describes three potential deployment types for a service: "ECS", "CODE_DEPLOY", and "EXTERNAL". When creating a new service you can choose between "ECS" or "CODE_DEPLOY".
I have an existing service. I checked the following places to find out its deployment type:
Its definition in Terraform
Its page in the AWS web console
Its entry in aws ecs describe-services --cluster=my-cluster --services=my-service
Not one of them mentions anything about a deployment type, nor any of the three enum values above. I'm guessing my service has the default deployment type, and that the default deployment type is "ECS", but I haven't found anything in the docs validating this.
How can I figure out my service's deployment type?
I understand it is bit confusing , well deployment type is called deployment controller , so you can pass the parameter to aws cli as deploymentController , if you do not pass anything then by default it takes 'ECS' , you can find more details for aws cli in the link below and we can use same parameter in terraform as well, I have provided you an example for terraform link.
https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateService.html#API_CreateService_RequestSyntax
resource "aws_ecs_service" "example" {
name = "example"
cluster = aws_ecs_cluster.example.id
deployment_controller {
type = "EXTERNAL"
}
}
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_service

How to update secret string using cludformation?

I am a newbie to AWS cloudformation, any help will appreciated.
I have a use case wherein I would like to write CFN to update already existing secret string. I was able to find a CFN to create a secret string but not to update.
I see the AWS CLI has aws secretsmanager update-secret --secret-id I was looking for similar option in Cloudformation.
Use cloud formation template for create secret but instead of creating stack, update the existing stack using change set.
but do it you must know the stack name which is created before to create secrets.
may be use the same template which used earlier just change the value and update stack

Update Docker image in ECS deploy

I deploy on AWS ECS a CloudFormation Stack, say teststack, via the command
aws cloudformation deploy --template-file ./CloudFormationTemplate.yml --stack-name teststack --force-upload
My stack executes a certain Docker image, say myname/myimage:latest.
I want to deploy & update the stack via a pipeline (I'm using GitLab, but I guess this is not relevant for the question of interest here).
In this setting, I may modify my Docker image without touching the CloudFormation Template file; I then build & push the new image myname/myimage:latest to my registry; finally, I trigger a new pipeline, which launches again the command aws cloudformation deploy ... --force-upload.
When executing aws cloudformation deploy ... --force-upload, the pipeline returns No changes to deploy. Stack stack-name is up to date.
Evidently, since the stack is executing the latest tagged images, it returns that everything is up to date, whitout making a pull of the new latest image.
Is there a way to force AWS CloudFormation to pull new Docker images from my registry?
Is using tags other than latest an option here? If so then you could tag the latest change you want to update let say myname/myimage:0-0-1 and then update the container definition in your cloudformation template to use this new tag.
If you wish to continue using the latest tag you probably cant force the deployment by a cloudformation template update. In my project when I didnt want to change the tag I ended up doing the update using AWS CLI:
aws ecs update-service --service ${ecsService} --cluster ${ecsCluster} --region ${region} --force-new-deployment

Mark Logic's cloud formation template not working in eu-west-1 region

I want to install MarkLogic solution in AWS eu-west-1 region using cloud formation template available in http://developer.marklogic.com/products/cloud/aws but the stack fails to create launch configuration.
I have downloaded the cloud formation template from the link http://developer.marklogic.com/products/cloud/aws and created a AWS cloud formation stack from "mlcluster.template" which is available in the above link but the stake failed during launch configuration set up. Not able to fix the template. Any suggestions ?
Problem got fixed. It is a configuration mistake.
For the IAM role parameter in AWS cloud formation stack I have to provide only the IAM name and not the entire ARN. Initially I provided the IAM ARN and it probably confused the resource name while creating an Auto Scaling Launch Configuration.