Skip to content

Commit

Permalink
Merge pull request #3 from robertasstankevicius/cdk-v2
Browse files Browse the repository at this point in the history
Upgrade CDK version from v1 to v2.
  • Loading branch information
laimonassutkus committed Aug 1, 2023
2 parents ec428ef + f4f6a98 commit 9a227af
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 50 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pipeline-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Pipeline

defaults:
run:
shell: bash

on:
push:
branches-ignore:
- master

jobs:
install-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: '18'

- uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install
run: |
python --version
node --version
npm --version
npm install -g aws-cdk
python -m pip install . --upgrade
python -m pip list
12 changes: 6 additions & 6 deletions .github/workflows/pipeline-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-node@v2-beta
- uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '18'

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.10'

- name: Install
run: |
python --version
node --version
npm --version
npm install -g aws-cdk@1.x
npm install -g aws-cdk
python -m pip install . --upgrade
python -m pip list
Expand Down
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release history

### 3.0.0
* Upgrade CDK support from v1 to v2.
* Update GitHub pipelines checkout, setup-node and setup-python versions.

### 2.4.1
* Fix package manifest.

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This is a full example where we create a lambda layer and use it in lambda funct

```python
from aws_cdk.aws_lambda import Function, Code, Runtime
from aws_cdk.core import Stack
from aws_cdk import Stack

from b_cfn_lambda_layer.lambda_layer import LambdaLayer
from b_cfn_lambda_layer.package_version import PackageVersion
Expand All @@ -107,7 +107,7 @@ layer = LambdaLayer(
# Or not specify it at all if you care only about dependencies.
# source_path=None,
source_path='/path/to/your/layer/source/code',
code_runtimes=[Runtime.PYTHON_3_6, Runtime.PYTHON_3_7, Runtime.PYTHON_3_8],
code_runtimes=[Runtime.PYTHON_3_8, Runtime.PYTHON_3_9, Runtime.PYTHON_3_10],
# You can conveniently specify dependencies to include.
dependencies={
'python-jose': PackageVersion.from_string_version('3.3.0'),
Expand All @@ -122,7 +122,7 @@ Function(
id='MyFunction',
code=Code.from_asset('/path/to/lambda/function/code'),
handler='index.handler',
runtime=Runtime.PYTHON_3_6,
runtime=Runtime.PYTHON_3_10,
# Specify layers.
layers=[layer]
)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.1
3.0.0
7 changes: 4 additions & 3 deletions b_cfn_lambda_layer/lambda_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from functools import lru_cache
from typing import List, Optional, Dict

from aws_cdk.aws_lambda import LayerVersion, Runtime, Function, ILayerVersion
from aws_cdk import Stack, DockerImage
from aws_cdk.aws_lambda import LayerVersion, Runtime, ILayerVersion, Function
from aws_cdk.aws_ssm import StringParameter
from aws_cdk.core import Stack, DockerImage

from b_cfn_lambda_layer.dependency import Dependency
from b_cfn_lambda_layer.lambda_layer_code import LambdaLayerCode
Expand Down Expand Up @@ -61,7 +61,8 @@ def __init__(
Runtime.PYTHON_3_6,
Runtime.PYTHON_3_7,
Runtime.PYTHON_3_8,
Runtime.PYTHON_3_9
Runtime.PYTHON_3_9,
Runtime.PYTHON_3_10
]
)

Expand Down
10 changes: 5 additions & 5 deletions b_cfn_lambda_layer/package_version.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

from enum import Enum
from typing import Optional


class PackageVersion:

class VersionType(Enum):

NONE = 'NONE'
SPECIFIC = 'SPECIFIC'
LATEST = 'LATEST'
Expand All @@ -23,13 +23,13 @@ def version_type(self) -> VersionType:
return self.__version_type

@classmethod
def from_string_version(cls, version_string: str) -> 'PackageVersion':
def from_string_version(cls, version_string: str) -> PackageVersion:
return cls(version=version_string, version_type=cls.VersionType.SPECIFIC)

@classmethod
def latest(cls) -> 'PackageVersion':
def latest(cls) -> PackageVersion:
return cls(version_type=cls.VersionType.LATEST)

@classmethod
def dont_install(cls) -> 'PackageVersion':
def dont_install(cls) -> PackageVersion:
return cls(version_type=cls.VersionType.NONE)
2 changes: 1 addition & 1 deletion b_cfn_lambda_layer_test/integration/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aws_cdk.core import App
from aws_cdk import App

from b_cfn_lambda_layer_test.integration.infrastructure.main_stack import MainStack

Expand Down
13 changes: 1 addition & 12 deletions b_cfn_lambda_layer_test/integration/cdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,5 @@
"app": "python3 app.py",
"pathMetadata": false,
"versionReporting": false,
"requireApproval": "never",
"toolkitStackName": "BCfnLambdaLayerToolkit",
"toolkitBucketName": "BCfnLambdaLayerBucket",
"context": {
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true",
"@aws-cdk/core:stackRelativeExports": "true",
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true,
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true,
"@aws-cdk/aws-kms:defaultKeyPolicies": true,
"@aws-cdk/aws-s3:grantWriteWithoutAcl": true
}
"requireApproval": "never"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from aws_cdk import Stack
from aws_cdk.aws_lambda import Runtime, Function, Code
from aws_cdk.core import Construct, Stack
from b_aws_testing_framework.tools.cdk_testing.testing_stack import TestingStack
from constructs import Construct

from b_cfn_lambda_layer.lambda_layer import LambdaLayer
from b_cfn_lambda_layer_test.integration.infrastructure.layer_cross_stack import root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aws_cdk import Stack
from aws_cdk.aws_lambda import Function, Code, Runtime
from aws_cdk.core import Stack
from b_aws_testing_framework.tools.cdk_testing.testing_stack import TestingStack

from b_cfn_lambda_layer.lambda_layer import LambdaLayer
Expand All @@ -11,6 +11,7 @@ class Function1(Function):
"""
Function that allows us to test whether installing dependencies works.
"""

def __init__(self, scope: Stack):
super().__init__(
scope=scope,
Expand All @@ -34,13 +35,13 @@ def __init__(self, scope: Stack):
'\n'
),
handler='index.handler',
runtime=Runtime.PYTHON_3_7,
runtime=Runtime.PYTHON_3_10,
layers=[
LambdaLayer(
scope=scope,
name=f'{TestingStack.global_prefix()}TestingLayer1',
source_path=root,
code_runtimes=[Runtime.PYTHON_3_7, Runtime.PYTHON_3_8],
code_runtimes=[Runtime.PYTHON_3_6, Runtime.PYTHON_3_7, Runtime.PYTHON_3_8, Runtime.PYTHON_3_9, Runtime.PYTHON_3_10],
dependencies={
'python-jose': PackageVersion.from_string_version('3.3.0'),
'boto3': PackageVersion.from_string_version('1.16.35'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aws_cdk.aws_lambda import Function, Code, Runtime
from aws_cdk.core import Stack
from aws_cdk import Stack
from b_aws_testing_framework.tools.cdk_testing.testing_stack import TestingStack

from b_cfn_lambda_layer.lambda_layer import LambdaLayer
Expand All @@ -11,6 +11,7 @@ class Function2(Function):
Function that allows us to test whether layer source code is included in the parent directory
i.e. instead of "from a import A" you would get "from parent_dir.a import A".
"""

def __init__(self, scope: Stack):
super().__init__(
scope=scope,
Expand All @@ -28,13 +29,13 @@ def __init__(self, scope: Stack):
'\n'
),
handler='index.handler',
runtime=Runtime.PYTHON_3_7,
runtime=Runtime.PYTHON_3_10,
layers=[
LambdaLayer(
scope=scope,
name=f'{TestingStack.global_prefix()}TestingLayer2',
source_path=root,
code_runtimes=[Runtime.PYTHON_3_7, Runtime.PYTHON_3_8],
code_runtimes=[Runtime.PYTHON_3_6, Runtime.PYTHON_3_7, Runtime.PYTHON_3_8, Runtime.PYTHON_3_9, Runtime.PYTHON_3_10],
)
]
)
13 changes: 7 additions & 6 deletions b_cfn_lambda_layer_test/integration/infrastructure/function3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aws_cdk import Stack, DockerImage
from aws_cdk.aws_lambda import Function, Code, Runtime
from aws_cdk.core import Stack, DockerImage
from b_aws_testing_framework.tools.cdk_testing.testing_stack import TestingStack

from b_cfn_lambda_layer.lambda_layer import LambdaLayer
Expand All @@ -12,6 +12,7 @@ class Function3(Function):
"""
Function that allows us to test whether multiple same layers override each other.
"""

def __init__(self, scope: Stack):
super().__init__(
scope=scope,
Expand All @@ -33,20 +34,20 @@ def __init__(self, scope: Stack):
'\n'
),
handler='index.handler',
runtime=Runtime.PYTHON_3_7,
runtime=Runtime.PYTHON_3_10,
layers=[
LambdaLayer(
scope=scope,
name=f'{TestingStack.global_prefix()}TestingLayer3_1',
source_path=root1,
code_runtimes=[Runtime.PYTHON_3_7, Runtime.PYTHON_3_8],
code_runtimes=[Runtime.PYTHON_3_6, Runtime.PYTHON_3_7, Runtime.PYTHON_3_8, Runtime.PYTHON_3_9, Runtime.PYTHON_3_10],
docker_image='python:3.8'
),
LambdaLayer(
scope=scope,
name=f'{TestingStack.global_prefix()}TestingLayer3_2',
source_path=root2,
code_runtimes=[Runtime.PYTHON_3_7, Runtime.PYTHON_3_8],
code_runtimes=[Runtime.PYTHON_3_6, Runtime.PYTHON_3_7, Runtime.PYTHON_3_8, Runtime.PYTHON_3_9, Runtime.PYTHON_3_10],
# Test backwards compatibility.
docker_image=DockerImage('python:3.8')
),
Expand All @@ -56,13 +57,13 @@ def __init__(self, scope: Stack):
scope=scope,
name=f'{TestingStack.global_prefix()}TestingLayer3_3_1',
source_path=root3,
code_runtimes=[Runtime.PYTHON_3_7, Runtime.PYTHON_3_8],
code_runtimes=[Runtime.PYTHON_3_6, Runtime.PYTHON_3_7, Runtime.PYTHON_3_8, Runtime.PYTHON_3_9, Runtime.PYTHON_3_10],
),
LambdaLayer(
scope=scope,
name=f'{TestingStack.global_prefix()}TestingLayer3_3_2',
source_path=root3,
code_runtimes=[Runtime.PYTHON_3_7, Runtime.PYTHON_3_8],
code_runtimes=[Runtime.PYTHON_3_6, Runtime.PYTHON_3_7, Runtime.PYTHON_3_8, Runtime.PYTHON_3_9, Runtime.PYTHON_3_10],
)
]
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aws_cdk import Stack
from aws_cdk.aws_lambda import Function, Code, Runtime
from aws_cdk.core import Stack
from b_aws_testing_framework.tools.cdk_testing.testing_stack import TestingStack

from b_cfn_lambda_layer.lambda_layer import LambdaLayer
Expand All @@ -22,7 +22,7 @@ def __init__(self, scope: Stack):
'\n'
),
handler='index.handler',
runtime=Runtime.PYTHON_3_7,
runtime=Runtime.PYTHON_3_10,
layers=[
LambdaLayer(
scope=scope,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aws_cdk.core import Construct
from b_aws_testing_framework.tools.cdk_testing.testing_stack import TestingStack
from constructs import Construct

from b_cfn_lambda_layer_test.integration.infrastructure.cross_stack_layers import CrossStackLayers
from b_cfn_lambda_layer_test.integration.infrastructure.function1 import Function1
Expand Down
2 changes: 1 addition & 1 deletion b_cfn_lambda_layer_test/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
b-aws-testing-framework>=0.0.24,<1.0.0
b-aws-testing-framework>=1.0.0,<2.0.0
boto3>=1.16.0,<2.0.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
long_description_content_type='text/markdown',
include_package_data=True,
install_requires=[
'aws-cdk.aws_lambda>=1.150.0,<2.0.0',
'aws-cdk.aws-ssm>=1.150.0,<2.0.0',
'aws-cdk-lib>=2.0.0,<3.0.0',
'aws-cdk-constructs>=2.0.0,<3.0.0',
],
author='Laimonas Sutkus',
author_email='[email protected]',
Expand Down

0 comments on commit 9a227af

Please sign in to comment.