Workbench Docker Image for Lambdas
Using the Workbench Docker Image for AWS Lambda Jobs allows your Lambda Jobs to use and create AWS ML Pipeline Artifacts with Workbench.
AWS, for some reason, does not allow Public ECRs to be used for Lambda Docker images. So you'll have to copy the Docker image into your private ECR.
Creating a Private ECR
You only need to do this if you don't already have a private ECR.
AWS Console to create Private ECR
- Open the Amazon ECR console.
- Choose "Create repository".
- For "Repository name", enter
workbench_base
. - Ensure "Private" is selected.
- Choose "Create repository".
Command Line to create Private ECR
Create the ECR repository using the AWS CLI:
Pulling Docker Image into Private ECR
Note: You'll only need to do this when you want to update the Workbench Docker image
Pull the Workbench Public ECR Image
Tag the image for your private ECR
docker tag public.ecr.aws/m6i5k1r2/workbench_base:latest \
<your-account-id>.dkr.ecr.<region>.amazonaws.com/<private-repo>:latest
Push the image to your private ECR
aws ecr get-login-password --region <region> --profile <profile> | \
docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
docker push <account-id>.dkr.ecr.<region>.amazonaws.com/<private-repo>:<tag>
Using the Docker Image for your Lambdas
Okay, now that you have the Workbench Docker image in your private ECR, here's how you use that image for your Lambda jobs.
AWS Console
- Open the AWS Lambda console.
- Create a new function.
- Select "Container image".
- Use the ECR image URI:
<account-id>.dkr.ecr.<region>.amazonaws.com/<private-repo>:<tag>
.
Command Line
Create the Lambda function using the AWS CLI:
aws lambda create-function \
--region <region> \
--function-name myLambdaFunction \
--package-type Image \
--code ImageUri=<account-id>.dkr.ecr.<region>.amazonaws.com/<private-repo>:<tag> \
--role arn:aws:iam::<account-id>:role/<execution-role>
Python CDK
Define the Lambda function in your CDK app:
from aws_cdk import (
aws_lambda as _lambda,
core
)
class MyLambdaStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
_lambda.Function(self, "MyLambdaFunction",
code=_lambda.Code.from_ecr_image("<account-id>.dkr.ecr.<region>.amazonaws.com/<private-repo>:<tag>"),
handler=_lambda.Handler.FROM_IMAGE,
runtime=_lambda.Runtime.FROM_IMAGE,
role=iam.Role.from_role_arn(self, "LambdaRole", "arn:aws:iam::<account-id>:role/<execution-role>"))
app = core.App()
MyLambdaStack(app, "MyLambdaStack")
app.synth()
Cloudformation
Define the Lambda function in your CloudFormation template.