'AWS SAM Template.yaml deploy does not use-container from launch.json in VSC
Using Visual Studio Code (VSC), I can get my Lambda's running locally and they build in a container, but when I go to deploy a container is not used, it's almost like it's ignoring the launch.json file. Are there other parameters I need to add for a deployment to work? The problem in the end is that Python is not found.
When debugging locally
2022-05-09 23:17:19 [INFO]: Preparing to debug locally: Lambda "app.lambda_handler"
2022-05-09 23:17:19 [INFO]: Building SAM application...
2022-05-09 23:17:19 [INFO]: Running command: (not started) [C:\Program Files\Amazon\AWSSAMCLI\bin\sam.cmd build --build-dir C:\Users\user\AppData\Local\Temp\aws-toolkit-vscode\vsctkqEogcB\output --template C:/code/MyProject/template.yaml --use-container --manifest C:\Users\user\AppData\Local\Temp\aws-toolkit-vscode\vsctkqEogcB\debug-requirements.txt]
2022-05-09 23:17:23 [INFO]: Starting Build inside a container
2022-05-09 23:17:23 [INFO]: Building codeuri: C:\code\MyProject\get-weather runtime: python3.7 metadata: {} architecture: x86_64 functions: ['GetWeatherFunction']
2022-05-09 23:17:24 [INFO]:
Fetching public.ecr.aws/sam/build-python3.7:latest-x86_64 Docker container image....
2022-05-09 23:17:24 [INFO]: ..
2022-05-09 23:17:24 [INFO]:
Mounting C:\code\EarthwiseGlobal\get-weather as /tmp/samcli/source:ro,delegated inside runtime container
When doing a deployment
2022-05-09 23:21:31 [INFO]: Starting SAM Application deployment...
2022-05-09 23:21:31 [INFO]: Building SAM Application...
2022-05-09 23:21:31 [INFO]: Running command: (not started) [C:\Program Files\Amazon\AWSSAMCLI\bin\sam.cmd build --build-dir C:\Users\user\AppData\Local\Temp\aws-toolkit-vscode\samDeployLHRBc5\build --template c:\code\MyProject\template.yaml]
2022-05-09 23:21:35 [INFO]: Building codeuri: c:\code\MyProject\get-weather runtime: python3.7 metadata: {} architecture: x86_64 functions: ['GetWeatherFunction']
2022-05-09 23:21:35 [INFO]: requirements.txt file not found. Continuing the build without dependencies.
2022-05-09 23:21:35 [INFO]:
Build Failed
2022-05-09 23:21:35 [INFO]: Error: PythonPipBuilder:Validation - Binary validation failed for python, searched for python in following locations : ['C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps\\python.EXE', 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python310\\python.EXE'] which did not satisfy constraints for runtime: python3.7. Do you have python for runtime: python3.7 on your PATH?
Template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: MyProject Serverless
Parameters:
ENV:
Description: 'Required. The environment for the deployment'
Type: 'String'
Globals:
Function:
Timeout: 3
Layers:
- !Sub arn
Environment:
Variables:
ENV: !Ref ENV
Architectures:
- x86_64
Resources:
GetWeatherFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: get-weather
CodeUri: get-weather/
Timeout: 30
Handler: app.lambda_handler
Runtime: python3.7
Policies:
- AWSLambdaBasicExecutionRole
- AmazonSSMReadOnlyAccess
launch.json
{
"version": "0.2.0",
"configurations": [
"type": "aws-sam",
"request": "direct-invoke",
"name": "GetWeatherFunction",
"invokeTarget": {
"target": "template",
"templatePath": "${workspaceFolder}/template.yaml",
"logicalId": "GetWeatherFunction"
},
"aws": {
"region": "us-east-1"
},
"sam": {
"containerBuild": true
},
"lambda": {
"memoryMb": 128,
"timeoutSec": 10,
"environmentVariables": {
"ENV": "DEV"
},
"payload": {
"json": {}
}
}
}
]
}
settings.json
{
"python.terminal.activateEnvInCurrentTerminal": true,
"python.defaultInterpreterPath": "${workspaceFolder}\\.venv\\Scripts\\Python.exe",
"python.terminal.activateEnvironment": true,
"terminal.integrated.env.windows": {"PYTHONPATH": "${workspaceFolder}\\.venv\\Scripts\\Python.exe"}
}
SAM version
sam --version
SAM CLI, version 1.46.0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
