user1101221
user1101221

Reputation: 414

How to deploy AWS-Lambda with boto3 and Docker?

Environment.
jupyterlab, python 3.8.
ubuntu 20.04LTS.
(Client : macos bigsur / google chrome).
using boto3.

Situation.
I builded docker image and pushed it to ECR successfully.
That image has awslambdaric and contains aws-lambda-rie.
I can deploy that image with AWS Lambda console.

I want.
Deploy it to lambda using boto3(=python code).

problem.
Following boto3 manual, deploying lambda is like next:

import boto3
lambdac = boto3.client('lambda')
dic = {
    'FunctionName':'lambda-name',
#    'Runtime':'python3.8',
    'Role':'my-role-arn',
    'Code':{'ImageUri':uri},
}
lambdac.create_function(**dic)

This make error.
It needs Runtime, so I added runtime (I think docker container version doesn't need runtime).
And run, and another error returns.

InvalidParameterValueException: An error occurred (InvalidParameterValueException) when calling the CreateFunction operation: Runtime and Handler are mandatory parameters for functions created with deployment packages.

The error makes me think "Isn't support boto3 deploy lambda with container?"
Because I didn't saw a example deploying container to lambda with boto3.

Question.
Is not boto3 supply deploying container to lambda?
Or Other boto3 function supplies it? (ecr client or others...).
Or is there any other method for python developing environment to deploy a container to lambda?

Upvotes: 1

Views: 2066

Answers (1)

user1101221
user1101221

Reputation: 414

I solved it myself.

the kwargs of create_function needs "PackageType":"Image"

import boto3
lambdac = boto3.client('lambda')
dic = {
    'FunctionName':'lambda-name',
    'Role':'my-role-arn',
    'Code':{'ImageUri':uri},
    'PackageType':'Image'   #add this parameter
}
lambdac.create_function(**dic)

Upvotes: 5

Related Questions