Provides infrastructure layer compute capabilities, including both bare metal and virtual servers with various optimizations includins compute, memory, IO, and disk. Also supports accelerations options such as GPUs, FPGAs, Inferentia and Trainium.
Provides image recognition capability for images (in batch or real-time) and video that provides a analysis of the content such as real-world objects, faces, celebrities, and path mapping.
Provides a publish/subscribe notification service with multiple subscription types including Amazon Simple Queue Service (SQS), Amazon Kinesis Data Firehose, AWS Lambda, generic HTTPS endpoints, SMS and email.
A serverless, fully-managed, message queue service that supports producing, store, and consuming messages and enables loose coupling between applications.
Provides private networking capability spanning multiple availability zones and supporting subnets, routing, network access control groups, security groups and gateways.
Provides tracing of service invocations in distributed applications for observability, allowing users to diagnose issues or optimize their service interactions.
All about Cloud, mostly about Amazon Web Services (AWS)
CloudFormation WaitCondition Resources
2017-07-22 / 611 words / 3 minutes
When using AWS CloudFormation, sometimes resources need time to initialize. For example, an Amazon Elastic Compute Cloud (EC2) instance using UserData to install multiple software packages could take several minutes. WaitCondition resources in conjunction with WaitHandle resources and the cfn-signal script signal completion, but it can be complex to setup. This post explains how to do it!
NOTE: AWS recommends using CloudFormation CreationPolicy attributes whenever possible. CreationPolicy attributes are simpler, but only work with Amazon EC2 and Auto Scaling resource types. See “” for more details.
WaitCondition resources also work with non-AWS resources and support the need for multiple resources.
WaitHandle
The WaitHandle resource is very simple but a little obscure. It has no properties. A WaitHandle actually creates an HTTP accessible endpoint linked to the WaitCondition. This HTTP endpoint is called by the cfn-signal script and the WaitCondition resource is evaluated.
In this example, the handle is called “WaitHandleName“.
WaitCondition
The WaitCondition resource ties everything together. It uses DependsOn to identify the CloudFormation resource that is the target of the wait condition.
It supports three properties:
The Count property defines the number of signals needed to satisfy the condition.
The Handle property refers to the associated WaitHandle resource.
The Timeout property defines the maximum duration to wait for the signal before the WaitCondition fails.
An example declaration would be:
WaitConditionName:
Type: “AWS::CloudFormation::WaitCondition”
DependsOn: “AppServerGroup”
Properties:
Handle:
Ref: “WaitHandleName”
Timeout: “300”
Count:
5
1
2
3
4
5
6
7
8
9
WaitConditionName:
Type: “AWS::CloudFormation::WaitCondition”
DependsOn: “AppServerGroup”
Properties:
Handle:
Ref: “WaitHandleName”
Timeout: “300”
Count:
5
In this example, the condition is called “WaitConditionName” and is associated with the “AppServerGroup” resource, meaning that the “AppServerGroup” will not be complete until the condition is met, or a timeout occurs. The condition is associated with the handle called “WaitHandleName“. The timeout is 300 seconds and there needs to be 5 signals sent before the condition is met.
cfn-signal
The final part of the puzzle is the cfn-signal script. cfn-signal is one of the CloudFormation Helper Scripts. It applies to WaitCondition resources and CreationPolicy attributes so the full syntax is a little complex. The AWS documentation does include specific syntax for use with WaitCondition resources:
cfn-signal
–success|-s signal.to.send
–reason|-r resource.status.reason
–data|-d data
–id|-i unique.id
–exit-code|-e exit.code
waitconditionhandle.url
1
2
3
4
5
6
7
cfn-signal
–success|-s signal.to.send
–reason|-r resource.status.reason
–data|-d data
–id|-i unique.id
–exit-code|-e exit.code
waitconditionhandle.url
Many of these options are irrelevant, or infrequently needed:
If the –exit-code (-e) option is used then the –success (-s) option is ignored .
The –reason (-r) option defaults to “Configuration Failed”. It is only used in the event of a failure.
The –id (-i) option ensures that multiple signals do not apply to the same resource. The id can be any alphanumeric string, and defaults to the ID of the Amazon EC2 instance or the machine’s Fully Qualified Domain Name (FQDN). This is adequate for most use cases.
The –data (-d) option returns arbitrary data.
As a result, the simplest possible call becomes:
cfn-signal -e
Within a UserData element the following syntax should be used:
All data and information provided on this site is for informational
purposes only. cloudninja.cloud makes no representations as to accuracy,
completeness, currentness, suitability, or validity of any information
on this site and will not be liable for any errors, omissions, or
delays in this information or any losses, injuries, or damages
arising from its display or use. All information is provided on an
as-is basis.
This is a personal weblog. The opinions expressed here represent my
own and not those of my employer. My opinions may change over time.