aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.51k stars 3.85k forks source link

DockerImageFunction: AttributeError: 'DockerImageFunction' object has no attribute 'Alias' #15702

Closed charleneleong-ai closed 3 years ago

charleneleong-ai commented 3 years ago

Cannot create Lambda alias for the DockerImageFunction.

Reproduction Steps

from aws_cdk import (
    aws_iam as iam,
    aws_ecr as ecr,
    aws_lambda,
    aws_apigatewayv2 as apigw,
    aws_codedeploy as codedeploy,
    aws_cloudwatch as cloudwatch,
    core
)

class InferenceStack(core.Stack):
    def __init__(self, 
                scope: core.Construct, 
                construct_id: str, 
                stage_name: str,
                config: dict,
                **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        lambda_function = aws_lambda.DockerImageFunction(
            scope=self,
            id='lambda-docker',
            function_name=name,
            description=f'Serverless Inference Lambda for {model_ecr_repository_uri}',
            code=ecr_image,
            memory_size=5120,
            role=lambda_role,
            environment={
                'MODEL_S3_URI': model_binary_location,
            },
            timeout=core.Duration.seconds(60)
        )

        lambda_alias = lambda_function.Alias(self, id='lambda-docker-alias',
                                            alias_name='latest',
                                            version=lambda_function.current_version)

app = core.App()

app.synth()

What did you expect to happen?

Since DockerImageFunction extends the aws_cdk.aws_lambda.Function base, I assumed we would be able to apply the functions to the DockerImageFunction class.

https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_lambda/DockerImageFunction.html

What actually happened?

When we try and CDK synth -

❯ cdk synth
distilbert-nlp-classification 20210704140013
Traceback (most recent call last):
  File "app.py", line 33, in <module>
    main()
  File "app.py", line 24, in main
    PipelineStack(scope=app, 
  File "/xxx/cdk_pipeline/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 83, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/xxx/cdk_pipeline/src/cdk_pipeline_stack.py", line 77, in __init__
    preprod_app = InferenceStage(self,
  File "/xxx/cdk_pipeline/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 83, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/xxx/cdk_pipeline/src/inference_stage.py", line 29, in __init__
    inference = InferenceStack(self, 
  File "/xxx/cdk_pipeline/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 83, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/xxx/cdk_pipeline/src/inference_stack.py", line 82, in __init__
    lambda_alias = lambda_function.Alias(self, id='lambda-docker-alias',
AttributeError: 'DockerImageFunction' object has no attribute 'Alias'
Subprocess exited with error 1

Environment

Other


This is :bug: Bug Report

peterwoodworth commented 3 years ago

Alias isn't an attribute. Read the docs here to learn about how to use aliases

github-actions[bot] commented 3 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.