Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to create custom stack names and API names #4951

Merged
merged 4 commits into from
Jun 21, 2018
Merged

Added ability to create custom stack names and API names #4951

merged 4 commits into from
Jun 21, 2018

Conversation

vt-cwalker
Copy link

What did you implement:

I implemented a feature that allows developers to customize their CloudFormation stack name and AWS API Gateway API name if they do not want to use the default of ${stage}-${service-name}.

Closes #2638

How did you implement it:

I added a check to see if certain properties were defined in the YAML, and if so, use it for the stack name or API name. If the properties are not defined, use the default as it has been

How can we verify it:

You will need to replace anything inside < and > in the config below

serverless.yml

service:
    name: ${self:custom.service.name}

# Add the serverless-webpack plugin
plugins:
    - serverless-webpack
    - serverless-dynamodb-local
    - serverless-offline
    - serverless-reqvalidator-plugin
    - serverless-aws-documentation
    - serverless-domain-manager
    - serverless-prune-plugin

provider:
    name: aws
    runtime: nodejs6.10
    memorySize: 512
    timeout: 10
    stackName: ${self:custom.service.label}
    apiName: ${self:custom.service.label}
    region: ${opt:region, 'us-east-1'}
    stage: ${opt:stage, 'dev'}
    versionFunctions: ${self:custom.lambda.versioning.${self:provider.stage}, 'false'}
    stackTags: # Optional CF stack tags
        ENV: ${self:provider.stage}
    deploymentBucket:
        name: www.${self:provider.region, 'us-east-1'}.${self:custom.domain}

functions:
    <FunctionName>:
        handler: index.submit
        name: ${self:custom.service.label}
        description: Manages database records
        onError: <ARN>
        tags:
            ENV: ${self:provider.stage}
        environment:
            ENV: ${self:provider.stage}
            TABLE_NAME: ${self:custom.service.label}
        events:
            - http:
                method: post
                path: /test-endpoint
                cors: true
        package:
            include:
                - index.js
        role: <ARN>

resources:
    Resources:
        <TableName>:
            Type: AWS::DynamoDB::Table
            Properties:
                TableName: ${self:custom.service.label}
                AttributeDefinitions:
                    - AttributeName: id
                      AttributeType: S
                KeySchema:
                    - AttributeName: id
                      KeyType: HASH
                SSESpecification:
                    SSEEnabled: true
                Tags:
                    - Key: "ENV"
                      Value: ${self:provider.stage}
                ProvisionedThroughput:
                    ReadCapacityUnits: ${self:custom.dynamodb.ReadCapacityUnits.${self:provider.stage}, 1}
                    WriteCapacityUnits: ${self:custom.dynamodb.WriteCapacityUnits.${self:provider.stage}, 1}
custom:
    domain: <domain>
    appName: '<App Name>'
    prefix: app-
    service:
        label: ${self:custom.prefix}${self:custom.stagePrefix.${self:provider.stage}, ''}test-service
        name: ${self:custom.prefix}test-service
    stagePrefix:
        dev: ${self:provider.stage}-
        staging: ${self:provider.stage}-
        prod: ''
    dynamodb:
        ReadCapacityUnits:
            dev: 1
            staging: 3
            prod: 3
        WriteCapacityUnits:
            dev: 1
            staging: 3
            prod: 5
    lambda:
        versioning:
            dev: false
            staging: true
            prod: true
    prune:
        automatic: ${self:custom.lambda.versioning.${self:provider.stage}, 'false'}
        number: 5
    api:
        domain:
            dev: api.${self:provider.stage}.${self:custom.domain}
            staging: api.${self:provider.stage}.${self:custom.domain}
            prod: api.${self:custom.domain}
    sslCert:
        dev:
            arn: <ARN>
            name: '*.${self:provider.stage}.${self:custom.domain}'
        staging:
            arn: <ARN>
            name: '*.${self:provider.stage}.${self:custom.domain}'
        prod:
            arn: <ARN>
            name: '*.${self:custom.domain}'
    customDomain:
        domainName: ${self:custom.api.domain.${self:provider.stage, 'dev'}}
        basePath: 'v1'
        stage: ${self:provider.stage}
        createRoute53Record: true
        certificateName: ${self:custom.sslCert.${self:provider.stage}.name}
        endpointType: edge

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@dls314
Copy link

dls314 commented Jun 5, 2018

@rts-cwalker @HyperBrain ,

If this PR addresses the concern in the earlier related PR is there any update to when it might be merged? This functionality would be very nice to have.

#4931 (review)

@vt-cwalker
Copy link
Author

@dls314 Yes this is the same PR as that one you referenced. Same functionality. Just need other customizations for my deploy process so i had to create a feature branch for this PR so i could use the master branch for my purposes only. 👍 So look forward to having this PR merged as well

Copy link
Member

@horike37 horike37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rts-cwalker
Thank you for your contribution 👍
Just reviewed the code and did some comments about if-check. Please see those.

And you also need to add the explanation of this feature to documentation, otherwise, everyone can not notice this one.

Would be a good place for this around here.
https://github.com/serverless/serverless/blob/master/docs/providers/aws/guide/serverless.yml.md

@@ -46,6 +46,10 @@ module.exports = {

// Stack
getStackName() {
if (this.provider.serverless.service.provider.stackName &&
this.provider.serverless.service.provider.stackName.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you check length? This should set string value, so I think would be good to use _.isString(this.provider.serverless.service.provider.stackName) instead of this.provider.serverless.service.provider.stackName.length > 0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. updated code and pushed changes. Just saw the link to update docs. So not quite ready to merge yet. Let me update docs as well

@@ -145,6 +149,10 @@ module.exports = {

// API Gateway
getApiGatewayName() {
if (this.provider.serverless.service.provider.apiName &&
this.provider.serverless.service.provider.apiName.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@horike37
Copy link
Member

@rts-cwalker
Thank you for the update 👍
It is perfect from my perspective! Just merge.

@horike37 horike37 merged commit 2eb915f into serverless:master Jun 21, 2018
@vt-cwalker vt-cwalker deleted the custom-stage-api-names branch June 22, 2018 00:26
@ahmed-abdulmoniem
Copy link

I think the documentation is not updated until now https://serverless.com/framework/docs/providers/aws/guide/services/

luclement pushed a commit to luclement/serverless that referenced this pull request Mar 19, 2019
add `stackName` and `apiName` to `serveless.yml` example
@luclement luclement mentioned this pull request Mar 21, 2019
7 tasks
pmuens added a commit that referenced this pull request Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to overwrite stack name
5 participants