Resources and plugins

Resources are any infrastructure that may support the functionality we are building with our function. For AWS, CloudFormation template syntax is used to define the resources. An example of this could be an Amazon DynamoDB table to provide a data persistence layer. We can specify the details of the AWS resource configuration in our serverless.yml file, and the framework will provision the infrastructure automatically when we deploy it. The following is an example of including a DynamoDB table called photosMetadata in the resources section of our serverless.yml file:

resources:
Resources:
photosMetadata
Type: AWS::DynamoDB::Table
Properties:
TableName: photosMetadata
AttributeDefinitions:
- AttributeName: id
AttributeType: N
KeySchema:
- AttributeName: id
AttributeType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1

Declaring additional resources is useful because it means we are keeping the other components of our infrastructure stack close to our business logic code. It also means that the infrastructure can be versioned and evolve at the same pace as our functions, all from one location. We can deploy the same definitions of resources, functions, and events to multiple AWS accounts, ensuring each environment is configured the same way.

Plugins are what we use to extend the framework. Everything in the Serverless Framework is made up of plugins, including the deploy CLI command. This makes the framework incredibly modular where we can swap out and replace functionality at any point. Plugins are really good for providing the extra things that are needed to fully implement our software life cycle. For example, you can install a plugin that will allow your functions to be unit tested. The plugin may also come with its own serverless CLI command so that you can build this into your continuous integration pipeline. To enable a plugin (or multiple plugins) after it has been installed locally, we can simply add the following to the plugins section in our serverless.yml file:

plugins:
  - serverless-kms-secrets

We'll explore an example of installing and using a plugin for testing in a Testing and debugging section where we learn about unit testing our functions. Plugins can be written by anyone in the community, and there are already heaps available to choose from. Now, we'll take a look at layers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.251.206