Hi guys, I am Aditya, trying to deploy a lambda f...
# general
g
Hi guys, I am Aditya, trying to deploy a lambda function using a docker image with pulumi, but m facing an issue where the image doesn't get updated when I makes changes to the Lambda function's handler, I have to manually update the image URI in the AWS console. Here is some code, that I am using.
Copy code
generate_embedding_lamda_image = docker_build.Image("generate-embedding-lamda-image",
    # Tag our image with our ECR repository's address.
    tags=[ecr_repository.repository_url.apply(lambda repository_url: f"{repository_url}:latest")],
    context=docker_build.BuildContextArgs(
        location="./lamdas/generate-embedding-lamda",
    ),
    # Use the pushed image as a cache source.
    cache_from=[docker_build.CacheFromArgs(
        registry=docker_build.CacheFromRegistryArgs(
            ref=ecr_repository.repository_url.apply(lambda repository_url: f"{repository_url}:latest"),
        ),
    )],
    # Include an inline cache with our pushed image.
    cache_to=[docker_build.CacheToArgs(
        inline=docker_build.CacheToInlineArgs(),
    )],
    # Build a multi-platform image manifest for ARM and AMD.
    platforms=[
        docker_build.Platform.LINUX_AMD64,
    ],
    # Push the final result to ECR.
    push=True,
    # Provide our ECR credentials.
    registries=[docker_build.RegistryArgs(
        address=ecr_repository.repository_url,
        password=auth_token.password,
        username=auth_token.user_name,
    )],
)
image_uri = ecr_repository.repository_url.apply(lambda repository_url: f"{repository_url}:latest")

# Create the Lambda function using the Docker image
lambda_function = aws.lambda_.Function(
    "generateEmbeddingLambda",
    package_type="Image",
    image_uri=image_uri,
    role=lambda_role.arn,
    timeout=300,
    memory_size=2048,
    architectures=["x86_64"],
)
q
It looks like the image uri isn't actually changing, is it? It's always pointing to the same tag
"{repository_url}:latest"
. The underlying image changes, but the tag pointing to it doesn't. The lambda function only sees the
image_uri
, and because that doesn't change it's not triggering an update. I'd recommend you to not use latest, but rather something like a semver tag or a hash generated from the docker context.