Home

Awesome

serverless-plugin-aws-resource-names

serverless

Serverless plugin to enable custom AWS resource names

Usage

Install the plugin to your project:

npm install serverless-aws-resource-names --save

Add the plugin and its configuration to your serverless project:

plugins:
  - serverless-aws-resource-names
custom:
  serverless-aws-resource-names:
    source: mapping.json

Create the mapping.json file in your project and modify the names to your hearts desire!

{
    "template": {
        "compiled": "cloudformation-template-update-stack.json",
        "core": "cloudformation-template-create-stack.json"
    },
    "stack": "$service-$stage",
    "role": {
        "Fn::Join": [
            "-", [
                "$service",
                "$stage",
                "$region",
                "lambdaRole"
            ]
        ]
    },
    "policy": {
        "Fn::Join": [
            "-", [
                "$stage",
                "$service",
                "lambda"
            ]
        ]
    },
    "apiGateway": "$stage-$service",
    "lambda": "$service-$stage-$lambda",
    "logGroup": "/aws/lambda/$service-$stage-$lambda"
}

Mapping Variable Reference

Custom Variables

You can define custom variables in your serverless.yml file:

plugins:
  - serverless-aws-resource-names
custom:
  serverless-aws-resource-names:
    source: mapping.json
    variables:
      functionSuffix: func

And then use these custom variables in your mapping.json file:

{
    "lambda": "$service-$stage-$lambda-$functionSuffix",
}

Here we've defined a custom variable functionSuffix and assigned it the value 'func'.

This will append the string 'func' to all of your Lambda function names.