cloudify-cosmo / cloudify-aws-plugin

A Cloudify Plugin that provisions resources in Amazon Web Services
Apache License 2.0
11 stars 29 forks source link

Unable to deploy cloudify.nodes.aws.lambda.Invoke #459

Open kbijakowski opened 2 years ago

kbijakowski commented 2 years ago

I tried to deploy example blueprint for provisioning of Lambda resource with Invoke object on AWS:

https://github.com/cloudify-cosmo/cloudify-aws-plugin/blob/3.0.6/examples/lambda-feature-demo/blueprint.yaml

as well as some custom blueprint using similar features. I used plugin v.3.0.6. In general support for Invoke object does not work. I discovered few issues:

1. botocore.exceptions.NoRegionError: You must specify a region. on cloudify_aws.lambda_serverless.resources.invoke.configure

For me it seems that it is caused by the usage of decorator here:

https://github.com/cloudify-cosmo/cloudify-aws-plugin/blob/3.0.6/cloudify_aws/lambda_serverless/resources/invoke.py#L27

Logic encapsulated in decorator code tries to instantiate and inject Boto3 client into the operation method. It fails due to lack of client_config as a property in cloudify.nodes.aws.lambda.Invoke type. Additionally, it seems that in this case decorating operation method is not required, because it only sets runtime_property without any interaction with AWS API.


2. cloudify.exceptions.NonRecoverableError: Missing resource ID! Node=lambda_function_invocation, Instance=lambda_function_invocation_f2agfn on cloudify_aws.lambda_serverless.resources.invoke.attach_to

Occurred after commenting out decorator usage described in 1. Here:

https://github.com/cloudify-cosmo/cloudify-aws-plugin/blob/3.0.6/cloudify_aws/lambda_serverless/resources/invoke.py#L34

aws_relationship(LambdaFunction decorator is used for operation executed on attach on relationship cloudify.relationships.aws.lambda.invoke.connected_to. So the relationship is: cloudify.nodes.aws.lambda.Invoke -> cloudify.nodes.aws.lambda.Function. It the decorator code I can see invocation of get_resource_id function:

https://github.com/cloudify-cosmo/cloudify-aws-plugin/blob/3.0.6/cloudify_aws/common/decorators.py#L195

In this invocation node and instance objects both are taken from the source of relationship. For mentioned relationship source is cloudify.nodes.aws.lambda.Invoke which has no AWS ID. IMHO in this case node / instance should be taken from the target of relationship. Also other usages of aws_relationship decorator may be checked.

This may be relevant of unlink too.


3. Issue in example - plain text unsupported as returned value from lambda

Occurred after introduction of a temporary fix (new decorator) for 2. Installation of deployment fails here:

https://github.com/cloudify-cosmo/cloudify-aws-plugin/blob/3.0.6/cloudify_aws/lambda_serverless/resources/function.py#L125

It is due to fact that example lambda function here:

https://github.com/cloudify-cosmo/cloudify-aws-plugin/blob/3.0.6/examples/lambda-feature-demo/function/main.py#L6

returns str instead of JSON. It works after changing value returned by lambda to JSON. But question is about support of other types than JSON.


I am opening a ticket instead of pushing fix because for me it seems that (mainly) 2. may be a broader issue.

kbijakowski commented 2 years ago

(logs attached) issue_1.log issue_2.log