
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
serverless-cloudformation-sub-variables
Advanced tools
Serverless framework plugin for easily supporting AWS CloudFormation Sub function variables
Add AWS CloudFormation Fn::Sub superpowers to your serverless.yml
.
This includes:
${SomeParameter}
${SomeResource}
${SomeResource.Attribute}
${AWS::Region}
${!LiteralVariable}
The trick is to use #{Something}
instead of ${Something}
in your serverless.yml
.
The plugin, during the package command, converts all the Sub function variables after the serverless variables are referenced and resolved, but before the CloudFormation template is packaged.
As part of the conversion, the Fn::Sub
wrapper is also added to the string. That is, something like #{Foo}-Bar-#{AWS::Region}
is converted to {"Fn::Sub": "${Foo}-Bar-${AWS::Region}"}
. If Fn::Sub
is already included in the direct parent node that contains the string with Sub function variables, then the Fn::Sub
wrapper is not added (this is the case when declaring Sub functions with key-value maps or when you want to be more explicit in your serverless.yml
).
This means that you can turn something like this:
service: awesome-service
plugins:
- serverless-cloudformation-sub-variables
...
resources:
...
Resources:
SomeResource:
Properties:
SomeProperty:
Fn::Sub:
- '#{CustomVariable}-XYZ'
- CustomVariable:
Fn::ImportValue: ABC-#{AWS::StackName}
Outputs:
MyBaseURL:
Value: https://#{ApiGatewayRestApi}.execute-api.#{AWS::Region}.amazonaws.com/${self:provider.stage}
Export:
Name: MyBaseURL
...
Into something like this:
...
"Resources": {
"SomeResource": {
"Properties": {
"SomeProperty": {
"Fn::Sub": [
"${CustomVariable}-XYZ",
{
"CustomVariable": {
"Fn::ImportValue": {
"Fn::Sub": "ABC-${AWS::StackName}"
}
}
}
]
}
}
}
}
"Outputs": {
"MyBaseURL": {
"Value": {
"Fn::Sub": "https://${ApiGatewayRestApi}.execute-api.${AWS::Region}.amazonaws.com/dev"
},
"Export": {
"Name": "MyBaseURL"
}
}
}
...
This works with anything in your serverless.yml
that ends up in the Serverless service's CloudFormation template, including the Resources and Outputs sections (and virtually every other location where Fn::Sub is supported).
npm install serverless-cloudformation-sub-variables
plugins
section of your serverless.yml
:plugins:
- serverless-cloudformation-sub-variables
serverless.yml
that have Sub variables as #{Something}
instead of ${Something}
Took a bit of inspiration from the following Serverless plugins, while looking for a more generic and simpler way to convert all kinds of non-custom Fn::Sub
variables, anywhere in the Serverless service's CloudFormation template:
FAQs
Serverless framework plugin for easily supporting AWS CloudFormation Sub function variables
The npm package serverless-cloudformation-sub-variables receives a total of 3,261 weekly downloads. As such, serverless-cloudformation-sub-variables popularity was classified as popular.
We found that serverless-cloudformation-sub-variables demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.