Using aws-sdk@client-ssm to retreive secure string using sam local start-api errors out

0

I'm using v3 version of the sdk on node v18.16.0.

In my apps.mjs, I used the following:

import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm";

When executing sam local start-api --env-vars env.json --profile default with a POST request. I am receiving the following error in the debug logs.

The docker spins up and is starts to listen, but once I make a POST request to the lambda endpoint, the following error occurs and you can see the debug logs below:

2023-10-12 13:59:58,259 | Reuse the created warm container for Lambda function 'TestWebhookFunction'                                                                      
2023-10-12 13:59:58,265 | Lambda function 'TestWebhookFunction' is already running                                                                                        
2023-10-12 13:59:58,269 | Starting a timer for 10 seconds for function 'TestWebhookFunction'                                                                              
START RequestId: 3944c01e-7b96-496f-8948-0870b7e77393 Version: $LATEST
END RequestId: 3944c01e-7b96-496f-8948-0870b7e77393
REPORT RequestId: 3944c01e-7b96-496f-8948-0870b7e77393  Duration: 2.37 ms       Billed Duration: 3 ms   Memory Size: 128 MB     Max Memory Used: 128 MB
2023-10-12 13:59:58,284 | Failed to deserialize response from RIE, returning the raw response as is                                                                       
2023-10-12 13:59:59,290 | Exception on /testwebhook [POST]                                                                                                                
Traceback (most recent call last):                                                                                                                                        
  File "flask/app.py", line 2190, in wsgi_app                                                                                                                             
  File "flask/app.py", line 1486, in full_dispatch_request                                                                                                                
  File "flask/app.py", line 1484, in full_dispatch_request                                                                                                                
  File "flask/app.py", line 1469, in dispatch_request                                                                                                                     
  File "samcli/local/apigw/local_apigw_service.py", line 719, in _request_handler                                                                                         
  File "samcli/local/apigw/local_apigw_service.py", line 612, in _invoke_lambda_function                                                                                  
  File "samcli/commands/local/lib/local_lambda.py", line 144, in invoke                                                                                                   
  File "samcli/lib/telemetry/metric.py", line 324, in wrapped_func                                                                                                        
  File "samcli/local/lambdafn/runtime.py", line 201, in invoke                                                                                                            
  File "samcli/local/docker/container.py", line 368, in wait_for_result                                                                                                   
  File "samcli/lib/utils/stream_writer.py", line 35, in write_bytes                                                                                                       
AttributeError: '_io.StringIO' object has no attribute 'buffer'              

This error goes away if I comment out the import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm";.

Does anyone know why? I ran aws cli get-parameter locally and my default profile and was able to retrieve the values.

dc
asked 7 months ago204 views
2 Answers
0
Accepted Answer

I have resolved this issue. This is due to the nodejs aws-sdk package compatibility with the x86_64 architecture which was specified in the template.yaml. I updated the architecture to arm64 in the template.yaml and this fixed the issue.

dc
answered 7 months ago
0

In Python, we get an Attribute Error if we attempt to access an attribute that does not belong to the object. The error you are observing is mentioned in this GitHub issue: https://github.com/PyCQA/flake8/issues/1445#issuecomment-964707246

AWS
SUPPORT ENGINEER
TheLich
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions