SAM regression: v3.31.0 does not use `aws.credentials` profile for local debugging
George-B-Simpson opened this issue · 10 comments
Problem
Using aws-sam debug profile to test a lambda locally. As of v3.31.0, the selected profile no longer is getting correctly passed down to our go libraries
Steps to reproduce the issue
When using a VSCode debug configuration like so...
{
"name": "PROD invoice upload",
"type": "aws-sam",
"request": "direct-invoke",
"invokeTarget": {
"target": "code",
"lambdaHandler": "lambda",
"projectRoot": "/some/src/code"
},
"aws": {
"region": "us-west-2",
"credentials": "profile:dev", <--------------- profile selected
},
"sam": {
"localArguments": ["--debugger-path=/home/vagrant/go/bin"],
"buildArguments": []
},
"lambda": {
"runtime": "go1.x",
"environmentVariables": {
....
The following go code no longer behaves as expected, instead getting an empty profile and defaulting everything to "us-east1"
"github.com/aws/aws-sdk-go-v2/config"
...
// Create aws configuration...
awsCfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
return err
}
// Then instantiate an S3 client object using the aws configuration
// (not to be confused with the cfg parameter passed into the Handler)
stsClient := sts.NewFromConfig(awsCfg)
...
Expected behavior
LoadDefaultConfig() uses the selected SSO profile from the VSCode debug config. Not 100% sure what the critical difference is... presumably some environmental variables are no longer being correctly passed through to SAM?
System details (run AWS: About
and/or Amazon Q: About
)
- OS: linux
- Visual Studio Code version: 1.93.0
- AWS Toolkit version: 3.31.0 (but NOT v3.29.0)
- Amazon Q version: irrelevant
Could you try the prerelease build to see if your issue is fixed? https://github.com/aws/aws-toolkit-vscode/releases/tag/prerelease
Yeah this is a potential issue here in 3.31.0, Please let me know if updating to 3.32.0 helps resolving this issue.
aws-toolkit-vscode/packages/core/src/shared/sam/localLambdaRunner.ts
Lines 290 to 293 in 8113288
This request was addressed in AWS Toolkit 3.32.0.
I'm not seeing any improvement in 3.33.0
2024-11-12 22:22:18,159 | Expand command line arguments to:
2024-11-12 22:22:18,159 | --template_file=/tmp/aws-toolkit-vscode/vsctk377a0222/output/template.yaml --event=/tmp/aws-toolkit-vscode/vsctk377a0222/event.json --env_vars=/tmp/aws-toolkit-vscode/vsctk377a0222/env-vars.json --debug_port=(5862,) --debugger_path=/home/vagrant/go/bin --debug_args=-delveAPI=2 --function_logical_id=lambda --no_event --layer_cache_basedir=/home/vagrant/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2024-11-12 22:22:18,159 | local invoke command is called
2024-11-12 22:22:18.162 [info] 2024-11-12 22:22:18,162 | No Parameters detected in the template
2024-11-12 22:22:18.177 [info] 2024-11-12 22:22:18,176 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lambda is lambda
2024-11-12 22:22:18.178 [info] 2024-11-12 22:22:18,177 | 1 stacks found in the template
2024-11-12 22:22:18,177 | No Parameters detected in the template
2024-11-12 22:22:18.188 [info] 2024-11-12 22:22:18,187 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lambda is lambda
2024-11-12 22:22:18,187 | 1 resources found in the stack
2024-11-12 22:22:18,187 | No Parameters detected in the template
2024-11-12 22:22:18.197 [info] 2024-11-12 22:22:18,197 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lambda is lambda
2024-11-12 22:22:18,197 | Found Serverless function with name='lambda' and CodeUri='lambda'
2024-11-12 22:22:18,197 | --base-dir is not presented, adjusting uri lambda relative to /tmp/aws-toolkit-vscode/vsctk377a0222/output/template.yaml
2024-11-12 22:22:18.203 [info] 2024-11-12 22:22:18,203 | Found one Lambda function with name 'lambda'
2024-11-12 22:22:18.203 [info] 2024-11-12 22:22:18,203 | Invoking lambda (go1.x)
2024-11-12 22:22:18,203 | Environment variables overrides data is standard format
2024-11-12 22:22:18.204 [info] 2024-11-12 22:22:18,203 | Loading AWS credentials from session with profile 'None'
Still seems to be getting AWS stuff from profile 'None' instead of the dev profile specified in the debug configuration.
@George-B-Simpson Thanks for the super detailed logs and description! I have identified the issue and the fix should be included in the next version. With this fix the region and credential in launch config should work correctly.
One thing to confirm, as region and credential works after this fix, I still see Loading AWS credentials from session with profile 'None'
in the log. I switched back to version 3.30 and it's showing the same log to me. Were you able to see other value in 3.30 other than None? Thanks
Oooh, good question. You're right, I do see the same message, even in the success case when running 3.30.0!
...
Commands you can use next
=========================
[*] Invoke Function: sam local invoke -t output/template.yaml
[*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch
[*] Deploy: sam deploy --guided --template-file output/template.yaml
2024-11-14 02:04:36.458 [info] 2024-11-14 02:04:36,457 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-11-14 02:04:36.458 [info] 2024-11-14 02:04:36,458 | Using config file: samconfig.toml, config environment: default
2024-11-14 02:04:36,458 | Expand command line arguments to:
2024-11-14 02:04:36,458 | --template_file=/tmp/aws-toolkit-vscode/vsctk05706e3d/output/template.yaml --event=/tmp/aws-toolkit-vscode/vsctk05706e3d/event.json --env_vars=/tmp/aws-toolkit-vscode/vsctk05706e3d/env-vars.json --debug_port=(5859,) --debugger_path=/home/vagrant/go/bin --debug_args=-delveAPI=2 --function_logical_id=lambda --no_event --layer_cache_basedir=/home/vagrant/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2024-11-14 02:04:36,458 | local invoke command is called
2024-11-14 02:04:36.461 [info] 2024-11-14 02:04:36,460 | No Parameters detected in the template
2024-11-14 02:04:36.474 [info] 2024-11-14 02:04:36,473 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lambda is lambda
2024-11-14 02:04:36.474 [info] 2024-11-14 02:04:36,474 | 1 stacks found in the template
2024-11-14 02:04:36.474 [info] 2024-11-14 02:04:36,474 | No Parameters detected in the template
2024-11-14 02:04:36.484 [info] 2024-11-14 02:04:36,483 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lambda is lambda
2024-11-14 02:04:36.484 [info] 2024-11-14 02:04:36,484 | 1 resources found in the stack
2024-11-14 02:04:36,484 | No Parameters detected in the template
2024-11-14 02:04:36.493 [info] 2024-11-14 02:04:36,493 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lambda is lambda
2024-11-14 02:04:36.494 [info] 2024-11-14 02:04:36,493 | Found Serverless function with name='lambda' and CodeUri='lambda'
2024-11-14 02:04:36,493 | --base-dir is not presented, adjusting uri lambda relative to /tmp/aws-toolkit-vscode/vsctk05706e3d/output/template.yaml
2024-11-14 02:04:36.499 [info] 2024-11-14 02:04:36,498 | Found one Lambda function with name 'lambda'
2024-11-14 02:04:36.499 [info] 2024-11-14 02:04:36,498 | Invoking lambda (go1.x)
2024-11-14 02:04:36,498 | Environment variables overrides data is standard format
2024-11-14 02:04:36.499 [info] 2024-11-14 02:04:36,499 | Loading AWS credentials from session with profile 'None'
2024-11-14 02:04:36.509 [info] 2024-11-14 02:04:36,509 | Resolving code path. Cwd=/tmp/aws-toolkit-vscode/vsctk05706e3d/output, CodeUri=/tmp/aws-toolkit-vscode/vsctk05706e3d/output/lambda
2024-11-14 02:04:36.509 [info] 2024-11-14 02:04:36,509 | Resolved absolute path to code is /tmp/aws-toolkit-vscode/vsctk05706e3d/output/lambda
2024-11-14 02:04:36,509 | Code /tmp/aws-toolkit-vscode/vsctk05706e3d/output/lambda is not a zip/jar file
2024-11-14 02:04:36.528 [info] 2024-11-14 02:04:36,527 | Skip pulling image and use local one: public.ecr.aws/sam/emulation-go1.x:rapid-1.41.0-x86_64.
...
Sorry for making a bad assumption there... this was one of those things where I wasn't looking too closely at the logs until it broke.
@George-B-Simpson if you can, please try the prerelease to confirm this issue is fixed.
The issue does appear to be fixed in v3.35.0-gc75e210