Skip to main content

AWS CDK package that helps deploying a lambda function into CodeStar.

Project description

AWS CodeStar CDK

A package used to deploy a lambda function into AWS CodeStar via CDK.

Description

This package creates a lambda function, editable via commits to AWS CodeCommit and fully monitored using AWS CodeStar. The function uses gradual code deployment Linear10PercentEvery3Minutes, which means any commits will gradually be deployed and 10 percent of the load will be sent to the new deployment every 3 minutes. If you want to change that, edit the line in

aws_codestar_cdk/files/source.zip/template.yml

More info: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/automating-updates-to-serverless-apps.html

The function's runtime is specified to python3.6 and the lambda handler (initially called code within your function) is specified to manage.runner (manage is the file name, a.k.a manage.py and runner is the function name within the file). All that can also be changed by editing the template.yml file.

Deploying this package creates 4 CloudFormation stacks in total.

The first one uploads the files toolchain.yml and source.zip into AWS S3, in order to be accessed by CodeStar.

The second stack is the CDK stack, that creates the CodeStar project.

The third stack is the CodeStar stack, which specifies, what the project should create. It's contents can be edited by editing

aws_codestar_cdk/files/toolchain.yml

The fourth stack is the lambda function stack, which can be edited by editing the template.yml file.

Prerequisites

In order to operate the package, you must first install it, using

pip install aws-codestar-cdk

You also need to have an AWS account with a confugured AWS CLI. Here's how to do it:

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

How to use

Import the main file into your project and call the Main classes constructor.

The arguments for the constructor are the scope, your project name, name of s3 bucket to put function source code and toolchain to, list of subnet IDs where the function should be deployed, list of security group IDs for the function, function invocation event type and event type arguments.

The subnet IDs specify, what subnets your function will be deployed to. Make sure they have NAT gateways, in order to access the internet. Read more:

https://docs.amazonaws.cn/en_us/vpc/latest/userguide/what-is-amazon-vpc.html

Function invocation event type can be "Api", "Schedule" or "None"

If the invocation type is schedule, argument schedule_expression is also required.

Is can be either:

rate(x units), meaning your function will be called every x units. e.g. rate(5 minutes), in which case the function will be invoked every 5 minutes.

cron(Minutes Hours Day-of-month Month Day-of-week Year) e.g. cron(0 0 * * ? *), which would mean, that the function will be invoked every day at midnight.

More info: https://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html

Parameters are split into 3 groups - VPC parameters, deployment parameters and Lambda type parameters. VPC parameters include subnet IDs and security group IDs.\n Lambda type parameters include event type and optionally schedule expressions.\n Deployment parameters include your project name and bucket name.

Your code should look something like this:

from aws_codestar_cdk.main import LambdaCodeStar
from aws_codestar_cdk.cdk_stack.parameters import VpcParameters, LambdaTypeParameters, DeploymentParameters

app = core.App()

deployment_params = DeploymentParameters('project_name', 'bucket_name')
lambda_params = LambdaTypeParameters(event_type="Schedule", schedule_expression="cron(0 0 * * ? *)")
vpc_params = VpcParameters(['subnet-1', 'subnet-2'], ['sg-1'])

main = LambdaCodeStar(app, vpc_params, deployment_params, lambda_params)

app.synth()

Release history

1.0.3

Add history file, update setup file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_codestar_cdk-1.0.3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

aws_codestar_cdk-1.0.3-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file aws_codestar_cdk-1.0.3.tar.gz.

File metadata

  • Download URL: aws_codestar_cdk-1.0.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/2.7.15+

File hashes

Hashes for aws_codestar_cdk-1.0.3.tar.gz
Algorithm Hash digest
SHA256 045e095c404c268f4ab7363a777610adab40a1376f6f38e3ff2618bc70772d4e
MD5 157861cb1c1b6da433b5996c96947507
BLAKE2b-256 4c74b528194b702bd3a431d69ffe723c96d6813ec186e5fd4f4bfe128c78d7b0

See more details on using hashes here.

File details

Details for the file aws_codestar_cdk-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: aws_codestar_cdk-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/2.7.15+

File hashes

Hashes for aws_codestar_cdk-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 396997475366cf4a7765a747155ce7e955bbb53ad1f557cefb835840850261bf
MD5 0d6ec8a22aea80f261c4f7e0ab1a351c
BLAKE2b-256 b732316d834ab2b1f8c03dbf196bae30e7c004b82a2dc948a82a8f8f1038fc6b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page