I am trying to use a SecureString in the meta data section of a cloud formation template but it raises the following error:
SSM Secure reference is not supported in: [AWS::EC2::Instance/Metadata/AWS::CloudFormation::Init/config/files/~/.ssh/content]
This is my code:
Resources:
LinuxEC2Instance:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Init:
config:
files:
~/.ssh:
content: !Sub |
'{{resolve:ssm-secure:/credentials/ansible:1}}'
mode: "000644"
owner: "ansible"
group: "ansible"
Why does this not work? I expected secure string references to work in Cloud Formation Templates?
To view instance metadata, you can only use the link-local address of 169.254. 169.254 to access. Requests to the metadata via the URI are free, so there are no additional charges from AWS. Using the curl tool on Linux or the PowerShell cmdlet Invoke-WebRequest on Windows, you will first create your token.
Instance metadata is data about your instance that you can use to configure or manage the running instance. Instance metadata is divided into categories, for example, host name, events, and security groups. You can also use instance metadata to access user data that you specified when launching your instance.
To be a managed instance, instances must meet the following prerequisites: Have the AWS Systems Manager Agent (SSM Agent) installed and running. Have connectivity with Systems Manager endpoints using the SSM Agent. Have the correct AWS Identity and Access Management (IAM) role attached.
Why does this not work?
It does not work because ssm-secure
is not supported for AWS::EC2::Instance
. The list of supported resources is here and it includes:
AWS::DirectoryService::MicrosoftAD
AWS::DirectoryService::SimpleAD
AWS::ElastiCache::ReplicationGroup
AWS::IAM::User
AWS::KinesisFirehose::DeliveryStream
AWS::OpsWorks::App
AWS::OpsWorks::Stack
AWS::OpsWorks::Stack
AWS::RDS::DBCluster
AWS::RDS::DBInstance
AWS::Redshift::Cluster
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With