Skip to content

Commit

Permalink
Merge pull request #139 from alexcasalboni/sdk-dependency
Browse files Browse the repository at this point in the history
Add explicit SDK dependency as Lambda Layer
  • Loading branch information
alexcasalboni committed Sep 15, 2021
2 parents c093322 + c1d8825 commit 0a2c55b
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -16,3 +16,5 @@ serverless.yml

.idea/
.vscode/

layer-sdk/src
10 changes: 8 additions & 2 deletions README-DEPLOY.md
Expand Up @@ -36,14 +36,20 @@ Now, you can clone this repository as follows:
$ git clone https://github.com/alexcasalboni/aws-lambda-power-tuning.git
```

Configure your deployment bucket name ([create one first!](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-bucket.html)) and stack name in the deployment script:
Configure your deployment bucket name ([create one first!](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-bucket.html)) and stack name in `scripts/deploy.sh`:


```bash
# config
BUCKET_NAME=your-sam-templates-bucket
STACK_NAME=lambda-power-tuning
PowerValues='128,512,1024,1536,3008'
# more config parameters are available too!
```

Build the SDK layer as follows:

```bash
$ bash scripts/build-layer.sh
```

You can finally deploy the serverless app:
Expand Down
102 changes: 102 additions & 0 deletions layer-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions layer-sdk/package.json
@@ -0,0 +1,11 @@
{
"name": "aws-sdk-layer",
"version": "1.0.0",
"description": "A layer used by Lambda functions in this project.",
"author": "Alex Casalboni <alex@alexcasalboni.com>",
"licence": "MIT-0",
"scripts": {},
"dependencies": {
"aws-sdk": "^2.989.0"
}
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {},
"devDependencies": {
"aws-sdk": "^2.945.0",
"aws-sdk": "^2.989.0",
"aws-sdk-mock": "^5.2.1",
"coveralls": "^3.0.3",
"eslint": "^6.1.0",
Expand Down
18 changes: 18 additions & 0 deletions scripts/build-layer.sh
@@ -0,0 +1,18 @@
#!/bin/bash

# make sure we're working on the layer folder
cd layer-sdk

# create subfolders
## ./src is referenced by the LayerVersion resource (.gitignored)
## ./src/nodejs will contain the node_modules
mkdir -p ./src/nodejs

# install layer dependencies (the SDK)
npm i

# clean up previous build ...
rm -rf ./src/nodejs/node_modules

# ... and move everything into the layer sub-folder
mv ./node_modules ./src/nodejs
19 changes: 19 additions & 0 deletions template.yml
Expand Up @@ -59,11 +59,24 @@ Globals:

Resources:

SDKlayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: AWS-SDK-v2_989_0
Description: AWS SDK 2.989.0
ContentUri: ./layer-sdk/src
CompatibleRuntimes:
- nodejs14.x
LicenseInfo: 'Available under the MIT-0 license.'
RetentionPolicy: Retain

initializer:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambda
Handler: initializer.handler
Layers:
- !Ref SDKlayer
Policies:
- AWSLambdaExecute # Managed Policy
- Version: '2012-10-17' # Policy Document
Expand All @@ -83,6 +96,8 @@ Resources:
Properties:
CodeUri: lambda
Handler: executor.handler
Layers:
- !Ref SDKlayer
Policies:
- AWSLambdaExecute # Managed Policy
- Version: '2012-10-17' # Policy Document
Expand All @@ -97,6 +112,8 @@ Resources:
Properties:
CodeUri: lambda
Handler: cleaner.handler
Layers:
- !Ref SDKlayer
Policies:
- AWSLambdaExecute # Managed Policy
- Version: '2012-10-17' # Policy Document
Expand All @@ -122,6 +139,8 @@ Resources:
Properties:
CodeUri: lambda
Handler: optimizer.handler
Layers:
- !Ref SDKlayer
Policies:
- AWSLambdaExecute # Managed Policy
- Version: '2012-10-17' # Policy Document
Expand Down

0 comments on commit 0a2c55b

Please sign in to comment.