Beginner Question: Mutliple services using the same resources

Hi there,

sorry if my questions sounds stupid, or if it has been answered yet. I was searching Google, StackOverflow and this forum without success.

In the most simple terms I need to build the system like this:

  • CSV-file gets downloaded by FTP parsed and data save in a dynamodb
  • API provides read and update access to the data, data gets enriched by some users inputs (API is consumed by a WebClient)
  • enriched data is exported into another CSV-file to be downloaded

I thought it would be a good idea, to separate these concerns into 3 serverless-services containing one or more functions:

  • Import service (one scheduled function for downloading csv to s3, one function for parsing csv and (perhaps another one for) saving data to DynamoDB)
  • API service (at least one function to list data and one to update data)
  • Export service (one scheduled function to read updated data an export csv to s3)

From the serverless-framework documentation I understand that each service has it own resources. But on the other hand all those services (and their respektive functions) need the same DynamoDB tables.

So my questions:

  • Am I able to create some kind of shared resources?
  • And If so, how?
  • If not, I figured I put all my functions in the same serverless-service, right? If so, how am I able to at least put them in some kind of namespace to make the distinction clear?

Hope someone could shed some light on this.

Kind regards

You can create Services with no functions thanks to @johncmckim’s PR for your shared resources.

You would then set the shared resources’ details as variables and pass them off to your code with environment variables.

Thank your very much, for your response.

Okay, nice…I was thinking about an function-less service for the resources.

I’m not sure if I understand the documentation. What I figured:

  1. create a service name resources and in the resource/serverless.yml define the something like

    resources:
    Resources:
    myTable:
    Type: AWS::DynamoDB::Table
    Properties:
    TableName: {opt:stage}-MyTable

  1. in the say they api/serverless.yaml I reference it like

    functions:
    hello:
    handler: handler.hello
    environment:
    MY_TABLE_NAME: ${file(…/resources/serverless.yml):resources.Resources.myTable.Properties.TableName}

Optionally I would define custom variables in the resources/serveless.yml so the path to reference is a little shorter.
Did I get that more or less correctly?

Kind regard, thomas

P.S.:
I’m coming from In serverless 0.5.6. There were the CloudFormation-Outputs which were stored in _meta and could be used and referenced as environment variables. Especially when ARNs are needed this comes in handy, right?
Does serverless-1.x handle it in a similar way? Or how do I get the details in to variables and into the environment of the other services?

Hi, I was wondering the same thing did it work for you?

Thanks,