I'm trying to make a very basic Lambda function using AWS CDK and This is what I"ve got so far
from constructs import Construct
from aws_cdk import (
Stack,
aws_lambda as _lambda,
aws_apigateway as apigw,
core,
)
class SportsTeamGeneratorStack(Stack):
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
my_lambda = _lambda.Function(self, 'HelloHandler',
runtime=_lambda.Runtime.PYTHON_3_7,
code=_lambda.Code.from_asset("lambda",
bundling= core.BundlingOptions(
image=_lambda.Runtime.PYTHON_3_9.bundling_image,
command=[
"bash", "-c",
"pip install --no-cache -r requirements.txt -t /asset-output && cp -au . /asset-output"
],
),
),
handler='hello.handler',
)
apigw.LambdaRestApi(
self, 'Endpoint',
handler=my_lambda,
)
Although I'm getting the following error: ImportError: cannot import name 'core' from 'aws_cdk'. I'm setting up my lambda this way because I'm trying to include external packages using python in the actual code, and want those files to be zipped up and given to s3. Any ideas?
CodePudding user response:
core
is not a module in aws_cdk
.
You can import the core package as core
using the following code:
import aws_cdk as core