Skip to content

Commit

Permalink
Merge pull request #235 from Lavanya0513/master
Browse files Browse the repository at this point in the history
Added python cdk
  • Loading branch information
alexcasalboni authored Mar 5, 2024
2 parents ee9b230 + 77cb3fd commit f1edca0
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 0 deletions.
1 change: 1 addition & 0 deletions cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Currently we support:

- [TypeScript](typescript/README.md)
- [C#](csharp/README.md)
- [Python](python/README.md)

You can use these projects as a standalone or reuse it within your own CDK projects.

Expand Down
46 changes: 46 additions & 0 deletions cdk/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# How to deploy the AWS Lambda Power Tuneing using the CDK for Python

This CDK project deploys *AWS Lambda Power Tuning* using Python.

You can use the project as a standalone or reuse it within your own CDK projects.


## CDK Prerequisites

See [here](../README.md).


## Language specific prerequisites

- [Python 3.6 or later](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_prerequisites)
- [Requirements for CDK with Python](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-python.html)

## Virtualenv setup and requirements

To manually create a virtualenv on MacOS and Linux:

```bash
$ python -m venv .venv
```

After the init process completes and the virtualenv is created, you can use the following
step to activate your virtualenv.

```bash
$ source .venv/bin/activate
```

If you are on Windows platform, you would activate the virtualenv like this:

```bash
% .venv\Scripts\activate.bat
```

Once the virtualenv is activated, you can install the required dependencies.
```bash
$ pip install -r requirements.txt
```

## Building, testing, and deploying the app
* `pytest` test this app
* `cdk deploy` deploy this app
28 changes: 28 additions & 0 deletions cdk/python/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
import os

import aws_cdk as cdk

from app.lambdapowertuner_stack import TheLambdaPowerTunerStack


app = cdk.App()
TheLambdaPowerTunerStack(app, "The-Lambda-Power-Tuner-Stack",
# If you don't specify 'env', this stack will be environment-agnostic.
# Account/Region-dependent features and context lookups will not work,
# but a single synthesized template can be deployed anywhere.

# Uncomment the next line to specialize this stack for the AWS Account
# and Region that are implied by the current CLI configuration.

#env=cdk.Environment(account=os.getenv('CDK_DEFAULT_ACCOUNT'), region=os.getenv('CDK_DEFAULT_REGION')),

# Uncomment the next line if you know exactly what Account and Region you
# want to deploy the stack to. */

#env=cdk.Environment(account='123456789012', region='us-east-1'),

# For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
)

app.synth()
40 changes: 40 additions & 0 deletions cdk/python/app/lambdapowertuner_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from aws_cdk import (
Stack
)
from constructs import Construct

from aws_cdk import aws_sam as sam



class TheLambdaPowerTunerStack(Stack):

def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

# The code that defines your stack goes here


stateMachineConfiguration= {
# "lambdaResource": "*",
# "PowerValues": "128,256,512,1024,1536,3008",
# "visualizationURL": "https://lambda-power-tuning.shw/",
# "totalExecutionTimeout": "300",
# "payloadS3Key": "*",
# "logGroupRetentionInDays": "7",
# "stateMachineNamePrefix": "powerTuningStateMachine",
# "permissionsBoundary": "<ARN of permission boundary>",
# "payloadS3Bucket": "<S3 bucket name used for large payloads>",
# "layerSdkName": "<name of the SDK layer>",
# "securityGroupIds": "<List of Security Groups to use in every Lambda function's VPC Configuration>",
# "subnetIds": "<List of Subnets to use in every Lambda function's VPC Configuration>"
}

cfn_application =sam.CfnApplication(
self, "SAR",
location={
"applicationId": "arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning",
"semanticVersion": "4.3.4"
},
parameters = stateMachineConfiguration
)
61 changes: 61 additions & 0 deletions cdk/python/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"app": "python app.py",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"requirements*.txt",
"source.bat",
"**/__init__.py",
"**/__pycache__",
"tests"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true
}
}
2 changes: 2 additions & 0 deletions cdk/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aws-cdk-lib==2.104.0
constructs>=10.0.0,<11.0.0
13 changes: 13 additions & 0 deletions cdk/python/source.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off

rem The sole purpose of this script is to make the command
rem
rem source .venv/bin/activate
rem
rem (which activates a Python virtualenv on Linux or Mac OS X) work on Windows.
rem On Windows, this command just runs this batch file (the argument is ignored).
rem
rem Now we don't need to document a Windows command for activating a virtualenv.

echo Executing .venv\Scripts\activate.bat for you
.venv\Scripts\activate.bat
17 changes: 17 additions & 0 deletions cdk/python/tests/unit/test_lambdapowertuner_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import aws_cdk as cdk
import aws_cdk.assertions as assertions

from app.lambdapowertuner_stack import TheLambdaPowerTunerStack

# example tests. To run these tests, uncomment this file along with the example
# resource in python/python_stack.py
def test_sar_app_created():
app = cdk.App()
stack = TheLambdaPowerTunerStack(app, "TheLambdaPowerTunerStack")
template = assertions.Template.from_stack(stack)

template.has_resource_properties("AWS::Serverless::Application", {
"Location":{
"ApplicationId": "arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning"
}
})

0 comments on commit f1edca0

Please sign in to comment.