Skip to content

Commit

Permalink
Merge 5df97fd into 7c39271
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcasalboni committed Jan 27, 2020
2 parents 7c39271 + 5df97fd commit 1a79abd
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README-SAR.md
Expand Up @@ -52,7 +52,7 @@ Additionally, you can specify a list of power values at deploy-time in the `Powe

### Usage in CI/CD pipelines

If you want to run the state machine as part of your continuous integration pipeline and automatically fine-tune your functions at every deployment, you can execute it with the script `execute.sh` (or similar) by providing the following input parameters:
If you want to run the state machine as part of your continuous integration pipeline and automatically fine-tune your functions at every deployment, you can execute it with the script `scripts/execute.sh` (or similar) by providing the following input parameters:

```json
{
Expand Down
14 changes: 8 additions & 6 deletions README.md
Expand Up @@ -24,13 +24,15 @@ Last but not least, the state machine will generate a dynamic visualization of a

## How to deploy the state machine (AWS Serverless Application Repository)

You can find this app in the [Serverless Application Repository](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:451282441545:applications~aws-lambda-power-tuning) and deploy it with just a few clicks.
You can find this app in the [Serverless Application Repository](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:451282441545:applications~aws-lambda-power-tuning) 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 the `scripts/deploy-sar-app.yml` and `scripts/deploy-sar-app.sh` files for a working reference.

## How to deploy the state machine (AWS SAM)

In case you want to deploy it "manually", you can run `deploy.sh`.
In case you want to deploy it "manually", you can run `scripts/deploy.sh`.

The script uses [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) to create a new CloudFormation stack in your account.
The script uses the [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) to create a new CloudFormation stack in your account.

First, install AWS SAM and [configure your AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration):

Expand Down Expand Up @@ -59,13 +61,13 @@ PowerValues='128,512,1024,1536,3008'
You can finally deploy the serverless app:

```bash
$ bash deploy.sh
$ bash scripts/deploy.sh
```


## How to execute the state machine (programmatically)

You can simply customize the input event in `sample-execution-input.json` and then run the `execute.sh` script. It will start a state machine execution, wait for the execution to complete, and then show the execution result in case of success.
You can customize the input event in `scripts/sample-execution-input.json` and then run the `scripts/execute.sh` script. It will start a state machine execution, wait for the execution to complete, and then show the execution results.

## How to execute the state machine (web console)

Expand Down Expand Up @@ -112,7 +114,7 @@ Additionally, you can specify a list of power values at deploy-time in the `Powe

### Usage in CI/CD pipelines

If you want to run the state machine as part of your continuous integration pipeline and automatically fine-tune your functions at every deployment, you can execute it with the script `execute.sh` (or similar) by providing the following input parameters:
If you want to run the state machine as part of your continuous integration pipeline and automatically fine-tune your functions at every deployment, you can execute it with the script `scripts/execute.sh` (or similar) by providing the following input parameters:

```json
{
Expand Down
9 changes: 9 additions & 0 deletions scripts/deploy-sar-app.sh
@@ -0,0 +1,9 @@
# config
BUCKET_NAME=your-sam-templates-bucket
STACK_NAME=lambda-power-tuning-app

# package
sam package --s3-bucket $BUCKET_NAME --template-file deploy-sar.yml --output-template-file packaged-sar.yml

# deploy
sam deploy --template-file packaged-sar.yml --stack-name $STACK_NAME --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM
20 changes: 20 additions & 0 deletions scripts/deploy-sar-app.yml
@@ -0,0 +1,20 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:

PowerTuningApp:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning
SemanticVersion: 3.2.0

# Parameters:
# PowerValues: 128,256,512,1024,1536,3008 # default RAM values
# lambdaResource: '*' # IAM permission (ARN or prefix)
# visualizationURL: https://lambda-power-tuning.show/ # you can use your own visualization URL

Outputs:
PowerTuningStateMachine:
Value: !GetAtt PowerTuningApp.Outputs.StateMachineARN
File renamed without changes.
4 changes: 2 additions & 2 deletions execute.sh → scripts/execute.sh
@@ -1,6 +1,6 @@
# config
STACK_NAME=lambda-power-tuning
INPUT=$(cat sample-execution-input.json) # or use a static string
INPUT=$(cat scripts/sample-execution-input.json) # or use a static string

# retrieve state machine ARN
STATE_MACHINE_ARN=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[?OutputKey==`StateMachineARN`].OutputValue' --output text)
Expand All @@ -22,7 +22,7 @@ do
sleep 1
elif test "$STATUS" == "FAILED"; then
# exit if failed
echo "The execution failed (check execution logs)"
echo -e "\nThe execution failed, you can check the execution logs with the following script:\naws stepfunctions get-execution-history --execution-arn $EXECUTION_ARN"
break
else
# print execution output if succeeded
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion template.yml
Expand Up @@ -4,7 +4,7 @@ Transform: AWS::Serverless-2016-10-31
Metadata:
AWS::ServerlessRepo::Application:
Name: aws-lambda-power-tuning
Description: AWS Step Functions state machine to optimize Lambda functions
Description: "AWS Lambda Power Tuning is an open-source tool that can help you visualize and fine-tune the memory/power configuration of Lambda functions. It runs in your own AWS account - powered by AWS Step Functions - and it supports three optimization strategies: cost, speed, and balanced."
Author: Alex Casalboni
SpdxLicenseId: Apache-2.0
LicenseUrl: LICENSE.txt
Expand Down

0 comments on commit 1a79abd

Please sign in to comment.