How To use case insensitive pattern tag Key value in AWS SSM Document run parameter? - amazon-web-services

We have a ssm document run parameter as below
RuntimeParameters:
targetKey: 'tag:{{ app }}'
Passing parameter value as below
app:
type: String
allowedPattern: '^[aA]pplication$'
default: Application
Now i want to allow application (small a) along with Application as key value for app.Is it possible to achieve this using regex?

Related

YAML Syntax for ImportValue into CFN Parameter Default

I'm struggling with the YAML syntax to import a value that was exported by another CFN stack into the default value of a parameter in a new stack.
What I have at the moment is:
Parameters:
DBEndpoint:
Description: Hostname endpoint for RDS Database
Type: String
Default: Fn::ImportValue: 'db-endpoint'
Where db-endpoint is the value exported by the following YAML template snippet:
Outputs:
dbhost:
Description: "RDS Endpoint Address"
Value: !GetAtt DB.Endpoint.Address
Export:
Name: db-endpoint
The export works fine, but I get a parse error (Template format error: YAML not well-formed. ) when trying to load the template with the ImportValue line.
Update:
I have the YAML parsing correctly now, I think, but now get a new error.
With
Parameters:
DBEndpoint:
Description: Hostname endpoint for RDS Database
Type: String
Default: !ImportValue 'db-endpoint'
I get an error Template format error: Every Default member must be a string..
So, it seems closer, but still not working.
This answer implies this might not even be possible... is that the case?
!ImportValue 'db-endpoint' can't be used in Parameters. It can only be used in Resources and Outputs of your template. You have to "manually" (aka, outside of CloudFormation, e.g. by a wrapper script) set the default value of DBEndpoint to the actual value of your db-endpoint.

AWS MSK Cloud Formation Tags problems

When creating AWS::MSK::Cluster with Cloud Formation I am not able to set Tags in the usual way:
Tags:
- Key: Name
Value: !Ref Identifier
Because of this error:
Property validation failure: [Value of property {/Tags} does not match type {Map}]
As of the time of writing, the documentation states that, instead of the usual Type: List of Tag, I should use: Type: Json.
Also the same documentation states that:
You can specify tags in JSON or in YAML, depending on which format you use for your template
After further investigation (and AWS support help), the working (only on creation) example looks like this:
Tags:
Name: !Ref Identifier
Additionally, tags cannot be modified (the docs actually state that tags change require replacement), when tried a slightly confusing error shows up:
CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename kafka-eu-west-1-dev and update the stack again.

AWS Systems Manager: Enumerate a StringList Parameter in State Manager Document

State Manager Documents allow us to define input parameters of type StringList. How can we enumerate each value in a StringList within the document definition?
Eg, imagine a StringList input parameter that defined a list of commands to run. How could we create a new aws:runShellScript action for each command in the list?
The pseudo-document below shows what I'm trying to achieve - creating a a new action for each value in a StringList.
schemaVersion: "2.2"
description: "Updates services configured for the current role"
parameters:
ListOfCommands:
type: "StringList"
description: "A list of commands to execute"
mainSteps:
/* For $C in ListOfCommands: */
- action: "aws:runShellScript"
name: "InstallConsul"
inputs:
runCommand:
- "{{$C}}"
According to AWS support, this is not currently possible. There is no way to enumerate any values in a StringList within the document itself.

How to store the entered parameters from cloudformation stack?

What I want to accomplish is to store the entered parameters from a Cloudformation stack.
For example: Imagine having two parameters param1 and param2.
I want to store the entered values either in DynamoDB, RDS Db, Etc.
I though in SNS notification:
Unfortunately, the notification's payload looks as follow:
StackId='arn:aws:cloudformation:us-east-1:accountId:stack/rfdsf/b6df0100-fd18-11e7-b3ab-500c2893c0d2'
Timestamp='2018-01-19T13:00:24.774Z'
EventId='b6df9d40-fd18-11e7-b3ab-500c2893c0d2'
LogicalResourceId='rfdsf'
Namespace='accountId'
PhysicalResourceId='arn:aws:cloudformation:us-east-1:accountId:stack/rfdsf/b6df0100-fd18-11e7-b3ab-500c2893c0d2'
PrincipalId='accountId'
ResourceProperties='null'
ResourceStatus='CREATE_IN_PROGRESS'
ResourceStatusReason='User Initiated'
ResourceType='AWS::CloudFormation::Stack'
StackName='rfdsf'
ClientRequestToken='Console-CreateStack-774eec95-c976-434c-b43b-ad3d295a0b9b'
As you can see, there is not any entered values.
Is it possible to store the entered parameters into a DB?
As suggested by #Rodrigigo M, You can save the params into SSM parameters store.
Description: "Create SSM Parameter"
Resources:
BasicParameter:
Type: "AWS::SSM::Parameter"
Properties:
Name: "param1"
Type: "String"
Value: "ABCD"
Description: "SSM Parameter for running date command."
AllowedPattern: "^[a-zA-Z]{1,10}$"
Also, if you want to save these into DB, you can create a Lambda to read them and store into DynamoDb or RDS.
In your cloudformation there is an Outputs parameter. You can output any value that was brought into the stack, so long as you explicitly specify which parameters you want to output.
Those values will be visible in the Outputs tab of cloudformation. If you want to move them to a database, such as DynamoDB, you can use the cloudformation:describeStacks api call to get all the output values for any stack.

Cloudformation AWS::ElasticLoadBalancingV2::Listener arbitrary list of certificates

I'm trying to write a CloudFormation template that will support multiple environments, and each env can have 2 or 3 certificates that should be attached to the load balancer listener.
However, since Cloudformation doesnt accept a simple list of certificate arns (doc), I'm struggling to figure out how to pass in a list of objects using parameters. It seems that:
Each parameter MUST have a type
"List" is not an acceptable type, it must be a list "of something"
Cloudformation does not have a "foreach" to create a "cert object" from each certificate arn on-the-fly.
I came across this example template (link), but here the problem is solved by using two explicit certificates - I need to be able to dynamically input an arbitrary list of certificates
For ref, I need to be able to inject something like this (pseudocode):
Certificates:
- Certificate: Arn1
- Certificate: Arn2
- Certificate: Arn_n
Where Arn1, Arn2, Arn_n comes from a "list-type" Parameter.
So I guess the question is: Is there any "foreach" or anything else in Cloudformation that could help me generate one "object" per item in a parameter list, or any way to pass in "rich" parameter objects?
CloudFormation allows you to use a CommaDelimitedList as a parameter type. You can then supply this in the form of a comma-separated list:
arn1,arn2,arn3
The list is arbitrary. You can then supply this into your listener's Certificates property directly:
"Certificates" : { "Ref" : "MyListParam" }