-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Hi,
When building Python custom resources we are mainly using three libraries:
- https://pypi.org/project/cloudformation-cli/
- https://pypi.org/project/cloudformation-cli-python-plugin/
- https://pypi.org/project/cloudformation-cli-python-lib/
Since the end of development preview for Python, we had python-plugin 2.0.0 and python-lib 2.0.0.
Both packages are located in this repository (https://github.com/aws-cloudformation/cloudformation-cli-python-plugin)
- cloudformation-cli-python-plugin: setup.py
- cloudformation-cli-python-lib: src/setup.py
In order to create a Python resource with cloudformation-cli, we need cloudformation-cli and cloudformation-cli-python-plugin installed. Everything is fine until there.
After running cfn init
; we end up with a requirements.txt
file containing this:
cloudformation-cli-python-lib==2.0.0
This file will later be used by SAM to package dependencies for the Lambda function.
Now if we try to build our resource with cfn generate && cfn submit --dry-run
we end up with a build/
directory containing everything our Lambda function needs.
The problem is that when SAM built the function, it read requirements.txt
file which is requiring a package called cloudformation-cli-python-lib
on PyPi (https://pypi.org/project/cloudformation-cli-python-lib/).
So in the end we expect something like this:
cloudformation-cli-python-plugin/src/cloudformation_cli_python_lib/utils.py
Lines 111 to 121 in d00dd26
@dataclass | |
class UnmodelledRequest: | |
clientRequestToken: str | |
desiredResourceState: Optional[Mapping[str, Any]] = None | |
previousResourceState: Optional[Mapping[str, Any]] = None | |
desiredResourceTags: Optional[Mapping[str, Any]] = None | |
systemTags: Optional[Mapping[str, Any]] = None | |
awsAccountId: Optional[str] = None | |
logicalResourceIdentifier: Optional[str] = None | |
nextToken: Optional[str] = None | |
region: Optional[str] = None |
But what we actually have in the build directory is like this:
cloudformation-cli-python-plugin/src/cloudformation_cli_python_lib/utils.py
Lines 111 to 117 in 21a7da9
@dataclass | |
class UnmodelledRequest: | |
clientRequestToken: str | |
desiredResourceState: Optional[Mapping[str, Any]] = None | |
previousResourceState: Optional[Mapping[str, Any]] = None | |
logicalResourceIdentifier: Optional[str] = None | |
nextToken: Optional[str] = None |
TLDR
cloudformation-cli-python-plugin and cloudformation-cli-python-lib are in the same repository but cloudformation-cli-python-lib package was not updated on PyPi with 2.1.0 release and now it is impossible to run tests because SAM uses PyPi to install requirements into the Lambda's build directory.
I think this critical because we cannot run tests anymore even after I rolled back to a previous CLI version (<=0.1.6) I get the following error when running cfn test
:
ERROR: usage: cfn [options] [file_or_dir] [file_or_dir] [...]
cfn: error: unrecognized arguments: --no-print-logs
inifile: /private/var/folders/bf/f_z6y6n959193x3csh_pcb0m0000gn/T/pytest_0da_6_7q.ini
rootdir: /path/to/my/resource
One or more contract tests failed
This issue is linked to #109