AWS::S3::Object
Instructions for CloudFormation Coverage New Issues Template
Quick Sample Summary:
- Title -> AWS::S3::Object
- Scope of request -> Add the ability to manage objects, like configuration, within CloudFormation templates
- Expected behavior -> I should be able to store object contents in JSON, YAML, text, or binary. I should be able to provide JSON and YAML objects as native CloudFormation (either JSON or YAML, and converting to my desired output format). Binary given as Base64. I should also be able to copy an object from another bucket.
- I should be able to write a YAML-formatted object from a JSON-formatted template.
- Links to existing API doc -> N/A
- Category tag -> Compute
- Additional context: This would allow the ability for configuration files to get written with references to a template, that can then get picked up at runtime by other users.
The ability to copy from another bucket would allow SAM to allow users to specify local paths and upload the files to a temporary bucket (along with code, etc.), and then CloudFormation could copy from there.
Example:
MyConfigObject:
Type: AWS::S3::Object
Properties:
Bucket: !Ref TheBucket
Key: /my/object/key
Value:
Json:
Key: Value
MyRef: !Ref SomeOtherResource
would write the following content:
{"Key":"Value","MyRef":"arn:aws:..."}
{
"MyConfigObject": {
"Type": "AWS::S3::Object",
"Properties": {
"Bucket": {"Ref": "TheBucket"},
"Key": "/my/object/key",
"Value": {
"Yaml": {
"Key": "Value",
"MyRef": {"Ref": "SomeOtherResource"}
}
}
}
}
}
would write the following content:
Key: Value
MyRef: arn:aws:...
There is a macro that helps with this issue to a degree. The macro converts the AWS::S3::Object into a custom resource which then uses lambda to add content into S3 however I agree this would be much better as a native object.
The AWS authored macro can be found here: https://github.com/aws-cloudformation/aws-cloudformation-templates/tree/main/CloudFormation/MacrosExamples/S3Objects
I actually have a newer version that uses crhelper which I adapted from this version and supports standard CloudFormation attributes such as DependsOn which is currently dropped by this version at the moment.