« A simple AWS resource naming strategy
July 4, 2020
AWSServerless
I’ve found the best way to name AWS resources is to use the following convention.
{stage-name}-{stack-name}-{resource-name}
This approach tells us 3 things just by looking at the resource name.
- Who deployed the resources.
- The cloudformation stack the resource belongs to.
- Finally, the resource name itself.
How do you do this with the Serverless Framework?
service: BillingDescription: The billing service.custom:stage: ${opt:stage, self:provider.stage}resourcePrefix: ${self:custom.stage}-${self:service.name}provider:stage: devfunctions:ProcessPaymentNotification:name: ${self:custom.resourcePrefix}-ProcessPaymentNotificationresources:Resources:PaymentsTable:Type: AWS::DynamoDB::TableProperties:TableName: ${self:custom.resourcePrefix}-Payments
Why not use Tags?
This naming convention is not a replacement for Tags. Tags are useful in many other ways.
It helps small teams that are sharing an AWS account identify and search resources easily. Creating separate AWS accounts, setting up federated billing and using AWS Control Tower can be a complicated solution for small teams. Many team’s end up using a single account for this reason. This naming convention is useful in such cases.