$ cat sample/000_sample.el
'( :a 1 :b 2 :c 3)
$ cat sample/000_sample.el | emacs --script lison-json.el -f batch-lison-json
{
"a": 1,
"b": 2,
"c": 3
}
'( :AWSTemplateFormatVersion "2010-09-09"
:Transform "AWS::Serverless-2016-10-31"
:Parameters
( :Prefix ( :Type "String")
:Env ( :Type "String"))
:Resources
( :ManualBucket
( :Type "AWS::S3::Bucket"
:DeletionPolicy "Retain"
:UpdateReplacePolicy "Retain"
:Properties
( :BucketName ( :Fn::Sub "${Prefix}-manual-${AWS::AccountId}")))
:ScriptBucket
( :Type "AWS::S3::Bucket"
:DeletionPolicy "Retain"
:UpdateReplacePolicy "Retain"
:Properties
( :BucketName ( :Fn::Sub "${Prefix}-script-${AWS::AccountId}"))))
:Outputs
( :ManualBucket
( :Value ( :Ref "ManualBucket")
:Export ( :Name ( :Fn::Sub "${Prefix}-ManualBucket")))
:ScriptBucket
( :Value ( :Ref "ScriptBucket")
:Export ( :Name ( :Fn::Sub "${Prefix}-ScriptBucket")))))
$ cat sample/001_s3.el | emacs --script lison-json.el -f batch-lison-json
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Parameters": {
"Prefix": {
"Type": "String"
},
"Env": {
"Type": "String"
}
},
"Resources": {
"ManualBucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
"Properties": {
"BucketName": {
"Fn::Sub": "${Prefix}-manual-${AWS::AccountId}"
}
}
},
"ScriptBucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
"Properties": {
"BucketName": {
"Fn::Sub": "${Prefix}-script-${AWS::AccountId}"
}
}
}
},
"Outputs": {
"ManualBucket": {
"Value": {
"Ref": "ManualBucket"
},
"Export": {
"Name": {
"Fn::Sub": "${Prefix}-ManualBucket"
}
}
},
"ScriptBucket": {
"Value": {
"Ref": "ScriptBucket"
},
"Export": {
"Name": {
"Fn::Sub": "${Prefix}-ScriptBucket"
}
}
}
}
}
lison is evaled, so you can use all Elisp for constructing JSON.
(progn
(defun bucket (name)
`( :Type "AWS::S3::Bucket"
:DeletionPolicy "Retain"
:UpdateReplacePolicy "Retain"
:Properties
( :BucketName ( :Fn::Sub ,(format "${Prefix}-%s-${AWS::AccountId}" name)))))
(defun list-parameters (&rest names)
(mapcan (lambda (name)
`(,(intern (concat ":" name)) (:Type "String")))
names))
(defun list-outputs (&rest names)
(mapcan (lambda (name)
`( ,(intern (concat ":" name))
( :Value ( :Ref ,name)
:Export ( :Name ( :Fn::Sub ,(format "${Prefix}-%s" name))))))
names))
`( :AWSTemplateFormatVersion "2010-09-09"
:Transform "AWS::Serverless-2016-10-31"
:Parameters
,(list-parameters
"Prefix"
"Env")
:Resources
( :ManualBucket ,(bucket "manual")
:ScriptBucket ,(bucket "script"))
:Outputs
,(list-outputs
"ManualBucket" "ScriptBucket")))
$ cat sample/002_s3_eval.el | emacs --script lison-json.el -f batch-lison-json
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Parameters": {
"Prefix": {
"Type": "String"
},
"Env": {
"Type": "String"
}
},
"Resources": {
"ManualBucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
"Properties": {
"BucketName": {
"Fn::Sub": "${Prefix}-manual-${AWS::AccountId}"
}
}
},
"ScriptBucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
"Properties": {
"BucketName": {
"Fn::Sub": "${Prefix}-script-${AWS::AccountId}"
}
}
}
},
"Outputs": {
"ManualBucket": {
"Value": {
"Ref": "ManualBucket"
},
"Export": {
"Name": {
"Fn::Sub": "${Prefix}-ManualBucket"
}
}
},
"ScriptBucket": {
"Value": {
"Ref": "ScriptBucket"
},
"Export": {
"Name": {
"Fn::Sub": "${Prefix}-ScriptBucket"
}
}
}
}
}