Bug: sam fails to build subdirectory based Dockerfile images on Windows #5345
Labels
area/cdk
area/docker
stage/waiting-for-release
Fix has been merged to develop and is waiting for a release
type/bug
Description:
sam build
fails to build images of which the Dockerfile is located in a sub-directory of the directory containing the assets, when using cdk on Windows andfromImageAsset
to construct a docker based lambda function.Such configuration is sometimes needed to share code between docker images. The image is built correctly when running
cdk deploy
, but not when I would like to build docker images usingsam build
for local testing withsam local invoke
.Here is an example:
The issue is likely related to Windows, as the docker images of the demo project are built correctly on Linux. A possible reason could be that aws:asset:dockerfile-path in build.toml contains an unix-style path:
However, using a windows-style path (myimage\\Dockerfile) as file parameter for
fromImageAsset
does not solve the problem.The issue is related but not identical to #4074, aws/aws-cdk#3342 and #4059.
Steps to reproduce:
Observed result:
2023-06-12 20:46:14,681 | Local image was not found.
2023-06-12 20:46:14,682 | Removing rapid images for repo testlambdafunctionc089708a
Building image......
2023-06-12 20:46:17,962 | Failed to build Docker Image
NoneType: None
2023-06-12 20:42:46,106 | Found Lambda function with name='TestLambdaFunctionC089708A' and Imageuri='testlambdafunctionc089708a'
2023-06-12 20:42:46,112 | Error occurred while trying to track an event: Event 'BuildFunctionRuntime' does not accept value 'None'.
2023-06-12 20:42:46,116 | Instantiating build definitions
2023-06-12 20:42:46,146 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(None, C:\Users\Timo\Documents\git\testcdk\cdk.out, Image, ,
eacc9958-29f8-4c8c-8ed2-9fb9e9aae05e, {'aws:cdk:path': 'TestcdkStack/TestLambdaFunction/Resource', 'aws:asset:path': 'asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123',
'aws:asset:dockerfile-path': 'myimage/Dockerfile', 'aws:asset:property': 'Code.ImageUri', 'Dockerfile': 'myimage\Dockerfile', 'DockerContext':
'C:\Users\Timo\Documents\git\testcdk\cdk.out\asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'DockerBuildArgs': {}}, {}, x86_64, []), Function:
Function(function_id='TestLambdaFunction', name='TestLambdaFunctionC089708A', functionname='TestLambdaFunction', runtime=None, memory=None, timeout=None, handler=None, imageuri='testlambdafunctionc089708a',
packagetype='Image', imageconfig=None, codeuri='C:\Users\Timo\Documents\git\testcdk\cdk.out', environment=None,
rolearn='arn:aws:lambda:us-east-1:XXXX:function:TestLambdaFunctionServiceRole0C9E0634', layers=[], events=None, metadata={'aws:cdk:path': 'TestcdkStack/TestLambdaFunction/Resource', 'aws:asset:path':
'asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'aws:asset:dockerfile-path': 'myimage/Dockerfile', 'aws:asset:property': 'Code.ImageUri', 'Dockerfile': 'myimage\Dockerfile',
'DockerContext': 'C:\Users\Timo\Documents\git\testcdk\cdk.out\asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'DockerBuildArgs': {}, 'SamNormalized': True, 'SamResourceId':
'TestLambdaFunction'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, stack_path='', runtime_management_config=None))
2023-06-12 20:42:46,171 | Building codeuri: C:\Users\Timo\Documents\git\testcdk\cdk.out runtime: None metadata: {'aws:cdk:path': 'TestcdkStack/TestLambdaFunction/Resource', 'aws:asset:path':
'asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'aws:asset:dockerfile-path': 'myimage/Dockerfile', 'aws:asset:property': 'Code.ImageUri', 'Dockerfile': 'myimage\Dockerfile',
'DockerContext': 'C:\Users\Timo\Documents\git\testcdk\cdk.out\asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'DockerBuildArgs': {}} architecture: x86_64 functions:
TestLambdaFunction
2023-06-12 20:42:46,174 | Building to following folder C:\Users\Timo\Documents\git\testcdk.aws-sam\build\TestLambdaFunctionC089708A
2023-06-12 20:42:46,176 | Building image for TestLambdaFunctionC089708A function
2023-06-12 20:42:46,190 | Setting DockerBuildArgs: {} for TestLambdaFunctionC089708A function
2023-06-12 20:42:46,525 | CDK Path for resource TestLambdaFunctionServiceRole0C9E0634 is ['TestcdkStack', 'TestLambdaFunction', 'ServiceRole', 'Resource']
2023-06-12 20:42:46,531 | CDK Path for resource TestLambdaFunctionC089708A is ['TestcdkStack', 'TestLambdaFunction', 'Resource']
2023-06-12 20:42:46,534 | CDK Path for resource CDKMetadata is ['TestcdkStack', 'CDKMetadata', 'Default']
2023-06-12 20:42:46,538 | 3 resources found in the stack
2023-06-12 20:42:46,540 | Found Lambda function with name='TestLambdaFunctionC089708A' and Imageuri='testlambdafunctionc089708a'
Build Succeeded
The build does not fail, but no docker image is built, as can be verified by
docker images
.Expected result:
docker images
should show the docker image corresponding to the lambda functionsam local invoke TestLambdaFunction -t cdk.out\TestcdkStack.template.json
should not fail, but run the docker based lambda functionAdditional environment details (Ex: Windows, Mac, Amazon Linux etc)
The text was updated successfully, but these errors were encountered: