{"library":"serverless-cloudformation-sub-variables","title":"Serverless CloudFormation Sub Variables Plugin","description":"This plugin for the Serverless Framework enhances `serverless.yml` files by automatically converting a custom `#{Variable}` syntax into AWS CloudFormation `Fn::Sub` functions. It supports a wide range of CloudFormation variables, including template parameters, resource logical IDs, resource attributes, pseudo parameters (e.g., `AWS::Region`), literal variables, and key-value map `Fn::Sub` functions. The plugin operates during the `package` command, executing its transformations after Serverless variables (`${self:variable}`) are resolved but before the CloudFormation template is packaged for deployment. A key feature is its ability to automatically wrap strings with `Fn::Sub` unless `Fn::Sub` is already explicitly defined in the parent YAML node, providing flexibility for complex scenarios. The current stable version is 0.2.1, released in late 2023, reflecting a deliberate, slower release cadence focused on stability and specific bug fixes. Its primary differentiator is the transparent and generic conversion of `#{...}` syntax across the entire CloudFormation template portion of `serverless.yml`, simplifying complex CloudFormation variable usage without extensive manual `Fn::Sub` declarations.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install serverless-cloudformation-sub-variables"],"cli":{"name":"serverless","version":null}},"imports":["plugins:\n  - serverless-cloudformation-sub-variables"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"npm install serverless-cloudformation-sub-variables\n\n# serverless.yml\nservice: my-sub-service\n\nplugins:\n  - serverless-cloudformation-sub-variables\n\nprovider:\n  name: aws\n  runtime: nodejs18.x\n  stage: dev\n  region: us-east-1\n\nresources:\n  Resources:\n    MyBucket:\n      Type: AWS::S3::Bucket\n      Properties:\n        BucketName: #{AWS::StackName}-#{self:provider.stage}-unique-bucket\n        Tags:\n          - Key: Environment\n            Value: #{AWS::Region}\n    MyLambdaRole:\n      Type: AWS::IAM::Role\n      Properties:\n        RoleName: #{AWS::StackName}-#{AWS::Region}-MyLambdaRole\n        AssumeRolePolicyDocument:\n          Version: '2012-10-17'\n          Statement:\n            - Effect: Allow\n              Principal:\n                Service: lambda.amazonaws.com\n              Action: sts:AssumeRole\n        ManagedPolicyArns:\n          - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole\noutputs:\n  BucketNameOutput:\n    Description: The name of the S3 bucket created by the service.\n    Value: #{MyBucket}\n    Export:\n      Name: #{AWS::StackName}-MyBucketName\n\n# To deploy after setting up serverless.yml\n# serverless deploy","lang":"javascript","description":"Demonstrates how to install the plugin via npm and configure it in `serverless.yml` to automatically convert `#{...}` syntax into `Fn::Sub` for CloudFormation resources and outputs, including pseudo-parameters and resource references.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}