Skip to content

Commit

Permalink
Merge branch 'master' into onlycoldstarts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcasalboni committed Mar 27, 2024
2 parents c0dd5ff + 97bf068 commit dd14172
Show file tree
Hide file tree
Showing 62 changed files with 9,600 additions and 1,138 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests-integration.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -33,4 +33,4 @@ jobs:
use-installer: true

- run: sam build --use-container
- run: sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --stack-name aws-lambda-power-tuning-gh-${GITHUB_REF_NAME/\//-} --s3-bucket ${{ secrets.AWS_S3_BUCKET }} --capabilities CAPABILITY_IAM --region ${{ secrets.AWS_REGION }}
- run: sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --stack-name aws-lambda-power-tuning-gh-${GITHUB_REF_NAME/\//-} --s3-bucket ${{ secrets.AWS_S3_BUCKET }} --capabilities CAPABILITY_IAM --region ${{ secrets.AWS_REGION }}
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [15.x, 16.x, 17.x, 18.x, 19.x]
node-version: [15.x, 16.x, 17.x, 18.x, 19.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -24,4 +24,4 @@ jobs:
- name: Coveralls
uses: coverallsapp/github-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions .gitignore
Expand Up @@ -5,6 +5,7 @@
node_modules
jspm_packages
venv
.venv
coverage
.nyc_output

Expand All @@ -22,3 +23,9 @@ layer-sdk/src
# ignore SAM CLI created files/dirs
.aws-sam/
samconfig.toml

# ignore terraform created files/dirs
.terraform/
.terraform.*
*.tfstate*
cid.log
99 changes: 49 additions & 50 deletions README-DEPLOY.md
@@ -1,21 +1,14 @@
# How to deploy the AWS Lambda Power Tuning tool

There are multiple options to deploy the tool.
There are 5 deployment options for deploying the tool using Infrastructure as Code (IaC).

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](https://aws.amazon.com/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)](#option1)
1. Manually [using the AWS SAM CLI](#option2)
1. Manually [using the AWS CDK](#option3)
1. The easiest way is to [deploy the app via the AWS Serverless Application Repository (SAR)](#option1).
1. [Using the AWS SAM CLI](#option2)
1. [Using the AWS CDK](#option3)
1. [Using Terraform by Hashicorp and SAR](#option4)
1. [Using native Terraform](#option5)

You can also [deploy manually with Terraform](#option5) by Hashicorp.

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

If you don't want to deal with any Infrastructure as Code tool, you can use one of the following:
1. The [Lumigo CLI](https://www.npmjs.com/package/lumigo-cli#lumigo-cli-powertune-lambda) (WARNING: deprecated)
1. The [Lambda Power Tuner UI](#option4)

Read more about the [deployment parameters here](README-INPUT-OUTPUT.md#state-machine-configuration-at-deployment-time).

Expand All @@ -28,12 +21,15 @@ You can also integrate the SAR app in your existing CloudFormation stacks - chec

## Option 2: Build and deploy with the AWS SAM CLI<a name="option2"></a>

**Note**: This method requires Docker.

1. Install the [AWS SAM CLI in your local environment](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html).

1. Configure your [AWS credentials (requires AWS CLI installed)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration):
```bash
$ aws configure
```
1. Install [Docker](https://docs.docker.com/get-docker/).
1. Clone this git repository:
```bash
$ git clone https://github.com/alexcasalboni/aws-lambda-power-tuning.git
Expand All @@ -45,24 +41,40 @@ You can also integrate the SAR app in your existing CloudFormation stacks - chec
```
[`sam build -u`](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html) 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.
1. Deploy the application using the SAM deploy "guided" mode:
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.
1. Deploy the application using the guided SAM deploy mode:
```bash
$ sam deploy -g
```
[`sam deploy -g`](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html) 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](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html#Concepts.RegionsAndAvailabilityZones.Regions) 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.
* 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`](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html) 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.

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.
SAM CLI will run the required commands to create the resources for the Lambda Power Tuning tool.

If there are no issues, once complete you will see the stack outputs and a `Successfully created/updated stack` message.
A successful deployment displays the message `Successfully created/updated stack`.
1. To delete Lambda Power Tuning, run
```bash
sam delete
```
Answer `Y` to the prompts.


## Option 3: Deploy the AWS SAR app with AWS CDK<a name="option3"></a>

1. [Install AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html) and [configure your AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration):

1. [Install AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html).
```bash
$ npm install -g aws-cdk
```

1. [Bootstrap](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_bootstrap) your account.

1. [Configure your AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration):

```bash
$ aws configure
```

Expand All @@ -74,7 +86,7 @@ You can also integrate the SAR app in your existing CloudFormation stacks - chec
new sam.CfnApplication(this, 'powerTuner', {
location: {
applicationId: 'arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning',
semanticVersion: '4.3.1'
semanticVersion: '4.3.4'
},
parameters: {
"lambdaResource": "*",
Expand All @@ -83,34 +95,21 @@ You can also integrate the SAR app in your existing CloudFormation stacks - chec
})
```

Alternatively, you can use [CDK Patterns](https://github.com/cdk-patterns/serverless) to give you a pre configured project in either TypeScript or Python:
Alternatively, you can build and deploy the solution from the source in this repo. See the following pages for language-specific instructions.

```bash
# For the TypeScript CDK version
npx cdkp init the-lambda-power-tuner
### TypeScript
See the [Typescript instructions](cdk/typescript/README.md)

# or for the Python CDK version
npx cdkp init the-lambda-power-tuner --lang=python
```

1. To deploy the TypeScript version you just need to:

```bash
cd the-lambda-power-tuner
npm run deploy
```

For Python deployment, see the instructions [here](https://github.com/cdk-patterns/serverless#2-download-pattern-in-python-or-typescript-cdk).

## Option 4: Deploy via AWS Lambda Power Tuner UI<a name="option4"></a>

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](https://github.com/mattymoomoo/aws-power-tuner-ui).
### Python
See the [Python instructions](cdk/python/README.md)

### go
See the [go instructions](cdk/go/README.md)

![Power Tuner UI](https://github.com/mattymoomoo/aws-power-tuner-ui/blob/master/imgs/website.png?raw=true)
### C\#
See the [Csharp instructions](cdk/csharp/README.md)

## Option 5: Deploy the SAR app with Terraform<a name="option5"></a>
## Option 4: Deploy the SAR app with Terraform<a name="option4"></a>

Simply add the `aws_serverlessapplicationrepository_cloudformation_stack` resource below to your Terraform code and deploy as usual through `terraform apply`.

Expand All @@ -120,7 +119,7 @@ resource "aws_serverlessapplicationrepository_cloudformation_stack" "lambda-powe
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.1"
# semantic_version = "4.3.4"
parameters = {
# All of these parameters are optional and are only shown here for demonstration purposes
Expand All @@ -137,11 +136,11 @@ See the [Terraform documentation](https://registry.terraform.io/providers/hashic

If you don't yet have a Terraform project, check out the [Terraform introduction](https://www.terraform.io/intro/index.html).

## Option 6: deploy natively with Terraform<a name="option6"></a>
## Option 5: Deploy natively with Terraform<a name="option5"></a>

Please see the documentation [here](terraform/Readme.md).
The Terraform modules are located in the [terraform](terraform) directory. Deployment documentation is [here](terraform/Readme.md).


## How to execute the state machine once deployed?
## How to execute the state machine once deployed

See [here](README-EXECUTE.md).
See the [execution](README-EXECUTE.md) instructions to run the state machine.
16 changes: 2 additions & 14 deletions README-EXECUTE.md
@@ -1,6 +1,6 @@
# How to execute the state machine

Independently of how you've deployed the state machine, you can execute it in a few different ways. Programmatically, using the AWS CLI, AWS SDK, or Lumigo CLI. Manually, using the AWS Step Functions web console or the Lambda Power Tuner UI.
Independently of how you've deployed the state machine, you can execute it in a few different ways. Programmatically, using the AWS CLI, or AWS SDK. Manually, using the AWS Step Functions web console.

## Option 1: Execute the state machine programmatically (CLI)

Expand All @@ -10,13 +10,7 @@ Feel free to customize the `scripts/sample-execution-input.json`, and then run `

The script will start a state machine execution, wait for the execution to complete (polling), and then show the execution results.

## Option 2: Execute the state machine programmatically (Lumigo CLI)

The Lumigo CLI integration takes care of both deploying and executing the SAR app transparently.

Check it out [here](README-DEPLOY.md#user-content-option-4-deploy-with-the-lumigo-cli).

## Option 3: Execute the state machine manually (web console)
## Option 2: Execute the state machine manually (web console)

Once the state machine is deployed, you can execute it and provide an input object.

Expand All @@ -41,10 +35,4 @@ Click "**Start Execution**" again and the execution will start. In the next page

Once the execution has completed, you will find the execution results in the "**Output**" tab of the "**Execution Details**" section at the top of the page. The output will contain the optimal power configuration and its corresponding average cost per execution.

## Option 4: Execute the state machine manually (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](https://github.com/mattymoomoo/aws-power-tuner-ui).

![Power Tuner UI](https://github.com/mattymoomoo/aws-power-tuner-ui/blob/master/imgs/website.png?raw=true)

0 comments on commit dd14172

Please sign in to comment.