There are 5 deployment options for deploying the tool using Infrastructure as Code (IaC).
- The easiest way is to deploy the app via the AWS Serverless Application Repository (SAR).
- Using the AWS SAM CLI
- Using the AWS CDK
- Using Terraform by Hashicorp and SAR
- Using native Terraform
Read more about the deployment parameters here.
You can find this app in the Serverless Application Repository and deploy it with just a few clicks in the AWS Management Console.
You can also integrate the SAR app in your existing CloudFormation stacks - check scripts/deploy-sar-app.yml and scripts/deploy-sar-app.sh for a sample implementation.
Note: This method requires Docker.
-
Install the AWS SAM CLI in your local environment.
-
Configure your AWS credentials (requires AWS CLI installed):
$ aws configure
-
Install Docker.
-
Clone this git repository:
$ git clone https://github.com/alexcasalboni/aws-lambda-power-tuning.git
-
Build the Lambda layer and any other dependencies (Docker is required):
$ cd ./aws-lambda-power-tuning $ sam build -u
sam build -u
will run SAM build using a Docker container image that provides an environment similar to that which your function would run in. SAM build in-turn looks at your AWS SAM template file for information about Lambda functions and layers in this project.Once the build completes successfully you will see output stating
Build Succeeded
. If the build is not successful, there will be error messages providing guidance on what went wrong. -
Deploy the application using the guided SAM deploy mode:
$ sam deploy -g
- For Stack Name, enter a unique name for the stack.
- For AWS Region, enter the region you want to deploy in.
Accept the defaults for all other prompts.
sam deploy -g
provides simple prompts to walk you through the process of deploying the tool. The responses are saved in a configuration file,samconfig.toml
, to be reused during subsequent deployments.SAM CLI will run the required commands to create the resources for the Lambda Power Tuning tool.
A successful deployment displays the message
Successfully created/updated stack
. -
To delete Lambda Power Tuning, run
sam delete
Answer
Y
to the prompts.
-
$ npm install -g aws-cdk
-
Bootstrap your account.
-
Configure your AWS credentials:
$ aws configure
-
If you already have a CDK project you can include the following to use the sam module:
import sam = require('@aws-cdk/aws-sam'); new sam.CfnApplication(this, 'powerTuner', { location: { applicationId: 'arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning', semanticVersion: '4.3.5' }, parameters: { "lambdaResource": "*", "PowerValues": "128,256,512,1024,1536,3008" } })
Alternatively, you can build and deploy the solution from the source in this repo. See the following pages for language-specific instructions.
See the Typescript instructions
See the Python instructions
See the go instructions
See the Csharp instructions
Simply add the aws_serverlessapplicationrepository_cloudformation_stack
resource below to your Terraform code and deploy as usual through terraform apply
.
resource "aws_serverlessapplicationrepository_cloudformation_stack" "lambda-power-tuning" {
name = "lambda-power-tuner"
application_id = "arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning"
capabilities = ["CAPABILITY_IAM"]
# Uncomment the next line to deploy a specific version
# semantic_version = "4.3.5"
parameters = {
# All of these parameters are optional and are only shown here for demonstration purposes
# See https://github.com/alexcasalboni/aws-lambda-power-tuning/blob/master/README-INPUT-OUTPUT.md#state-machine-input-at-deployment-time
# PowerValues = "128,192,256,512,1024,2048,3072,4096,5120,6144,7168,8192,9216,10240"
# lambdaResource = "*"
# totalExecutionTimeout = 900
# visualizationURL = "https://lambda-power-tuning.show/"
}
}
See the Terraform documentation for more configuration options of aws_serverlessapplicationrepository_cloudformation_stack
.
If you don't yet have a Terraform project, check out the Terraform introduction.
The Terraform modules are located in the terraform directory. Deployment documentation is here.
See the execution instructions to run the state machine.