Create SimpleDB domain using serverless.yaml

288 views Asked by At

So I am creating a server less application on Amazon AWS using the Serverless Framework. For our stack, we create a number of Lambda functions, DynamoDB table, API Gateway and now we want to add a simpleDB domain as well. I cannot seem to find any information online on what code snippet to add to serverless.yaml to create a SimpleDB domain.

I wrote the following code, which creates the domain but the name of the domain is not as expected

resources:
  Resources:
    LogSimpleDBTable:
      Type: "AWS::SDB::Domain"
      Properties:
        DomainName : ${self:provider.environment.SIMPLEDB}
        Description: "SDB Domain to store data log"

And the variable SimpleDB is defined as

SIMPLEDB: git-pushr-processing-${opt:stage, self:provider.stage}

So when I deploy using the command

serverless deploy --stage staging --awsaccountid XXXXX

I expect the name of the SimpleDB table to be

git-pushr-processing-staging

instead I get a domain with the following name

git-pushr-api-staging-LogSimpleDBTable-1P7CQH4SGAWGI

Where the last bit of sequence (1P7CQH4SGAWGI) varies every time.

We are using the exact same pattern to name our DynamoDB tables and they seem to get created with correct name

 DYNAMODB_TABLE: git-pushr-processing-${opt:stage, self:provider.stage}

resources:
  Resources:
    TodosDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:provider.environment.DYNAMODB_TABLE}
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

We get a DynamoDB table with the following name

git-pushr-processing-staging

So what am I doing wrong here ?

1

There are 1 answers

0
Troggy On

I don't know how to make serverless use the domain name of your choice.

However, it is possible to reference the domain generated using Ref: LogSimpleDBTable syntax

E.g. to pass the domain name to lambda (making it available as process.env.SDB_DOMAIN_NAME variable):

functions:
  queueRequests:
    handler: src/consumer.handler
    name: consumer
    environment:
      SDB_DOMAIN_NAME:
        Ref: LogSimpleDBTable

Or reference it in IAM role statements

provider:
  ...
  iamRoleStatements:
    - Effect: Allow
      Action:
        - sdb:GetAttributes
        - sdb:PutAttributes
      Resource: 
        Fn::Join:
          - ""
          - - "arn:aws:sdb:*:*:domain/"
            - Ref: LogSimpleDBTable