Skip to content

Latest commit

 

History

History
147 lines (102 loc) · 7.83 KB

README-DEPLOY.md

File metadata and controls

147 lines (102 loc) · 7.83 KB

How to deploy the AWS Lambda Power Tuning tool

There are multiple options to deploy the tool.

If you are familiar with Infrastructure as Code, there are 4 ways for you to create all of the resources necessary for Lambda Power Tuning.

The following three options utilize AWS CloudFormation on your behalf to create the necessary resources. Each will create a new CloudFormation stack in your AWS account containing all the resources for the Lambda Power Tuning tool.

  1. The easiest way is to deploy the app via the AWS Serverless Application Repository (SAR)
  2. Manually using the AWS SAM CLI
  3. Manually using the AWS CDK

You can also deploy manually with Terraform by Hashicorp.

If you want to use Terraform natively (which circumvents Cloudformation), see Option 6

If you don't want to deal with any Infrastructure as Code tool, you can use one of the following:

  1. The Lumigo CLI (WARNING: deprecated)
  2. The Lambda Power Tuner UI

Read more about the deployment parameters here.

Option 1: AWS Serverless Application Repository

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.

Option 2: Build and deploy with the AWS SAM CLI

  1. Install the AWS SAM CLI in your local environment.

  2. Configure your AWS credentials (requires AWS CLI installed):

    $ aws configure
  3. Clone this git repository:

    $ git clone https://github.com/alexcasalboni/aws-lambda-power-tuning.git
  4. 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 has completed you should see output that states Build Succeeded. If not there will be error messages providing guidance on what went wrong.

  5. Deploy the application using the SAM deploy "guided" mode:

    $ sam deploy -g

    sam deploy -g will provide simple prompts to walk you through the process of deploying the tool. Provide a unique name for the 'Stack Name' and supply the AWS Region you want to run the tool in and then you can select the defaults for testing of this tool. After accepting the prompted questions with a "Y" you can optionally save your application configuration.

    After that the SAM CLI will run the required commands to create the resources for the Lambda Power Tuning tool. The CloudFormation outputs shown will highlight any issues or failures.

    If there are no issues, once complete you will see the stack outputs and a Successfully created/updated stack message.

Option 3: Deploy the AWS SAR app with AWS CDK

  1. Install AWS CDK and configure your AWS credentials:

    $ npm install -g aws-cdk
    $ aws configure
  2. 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.2'
      },
      parameters: {
        "lambdaResource": "*",
        "PowerValues": "128,256,512,1024,1536,3008"
      }
    })

    Alternatively, you can use CDK Patterns to give you a pre configured project in either TypeScript or Python:

    # For the TypeScript CDK version
    npx cdkp init the-lambda-power-tuner
    
    # or for the Python CDK version
    npx cdkp init the-lambda-power-tuner --lang=python
  3. To deploy the TypeScript version you just need to:

    cd the-lambda-power-tuner
    npm run deploy

    For Python deployment, see the instructions here.

Option 4: Deploy via AWS Lambda Power Tuner UI

You can deploy and interact with Lambda Power Tuning with an ad-hoc web interface. This UI will deploy everything you need to power-tune your functions and also simplify the input/output management for Step Functions via API Gateway.

You can find the open-source project and the instructions to deploy it here: mattymoomoo/aws-power-tuner-ui.

Power Tuner UI

Option 5: Deploy the SAR app with Terraform

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.2"

  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.

Option 6: deploy natively with Terraform

Please see the documentation here.

How to execute the state machine once deployed?

See here.