Error running a module on boto3

0

Note: New on AWS | Post_1 | Edit the question if necessary

Started practicing building a Py-based app on AWS (region = 'ap-south-1') with a publicly available tutorial by AWS. While exploring the SDK, I made a client, a resource, and this (app.py) file. When I ran app.py to fetch and list the Dragon data hosted for the demo purpose, it bounced back with some errors. The parameter bucket could be making the error but could the region be making any problems as well? if the API call is right, then what could make this problem? Inserted both code and the error:

import boto3

s3 = boto3.resource('s3', 'us-east-1').meta.client
ssm = boto3.client('ssm', 'us-east-1')
bucket_name = ssm.get_parameter(Name= 'dragon_data_bucket_name',WithDecryption=False)['Parameter']['value'] #Systems Manager
file_name = ssm.get_parameter(Name= 'dragon_data_file_name',WithDecryption=False)['Parameter']['value'] #Systems Manager

def listDragons():
    
    expression = "select * from s3object s" #SQL
    
    result = s3.select_object_content(
            Bucket= bucket_name,
            key= file_name,
            ExpressiopnType= 'SQL',
            Expression=expression,
            InputSerialization= {'JSON': {'Type':'Document'}}, #document type
            OutpuSerialization= {'JSON': {}}
    )
    
    for event in result ['Payload']: #Looping the events
        if 'Records' in event:
            print(event['Records']['Payload'].decode('utf-8'))

listDragons()   

Error:

Traceback (most recent call last):
  File "app.py", line 7, in <module>
    bucket_name= ssm.get_parameter(Name= 'dragon_data_bucket_name',WithDecryption='False')['Parmaeter']['value'] #Systems Manager
  File "/home/ec2-user/.local/lib/python3.7/site-packages/botocore/client.py", line 514, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/ec2-user/.local/lib/python3.7/site-packages/botocore/client.py", line 902, in _make_api_call
    api_params, operation_model, context=request_context
  File "/home/ec2-user/.local/lib/python3.7/site-packages/botocore/client.py", line 963, in _convert_to_request_dict
    api_params, operation_model
  File "/home/ec2-user/.local/lib/python3.7/site-packages/botocore/validate.py", line 381, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter WithDecryption, value: False, type: <class 'str'>, valid types: <class 'bool'>

2 Answers
0

Your logs and code are not the same. In the logs, the code is giving an error due to this block: bucket_name= ssm.get_parameter(Name= 'dragon_data_bucket_name',WithDecryption='False')['Parmaeter']['value']

While in the code section, the syntax is correct: bucket_name = ssm.get_parameter(Name= 'dragon_data_bucket_name',WithDecryption=False)['Parameter']['value']

The error is due to a syntax error in your API call. The WithDecryption parameter for ssm.get_parameter API takes a bool value while you provided a string by enclosing it in quotes. Remove the quotes on your API call and it will work fine. Below is the updated API call syntax:

bucket_name = ssm.get_parameter(Name= 'dragon_data_bucket_name',WithDecryption=False)['Parameter']['value']

Please validate that you have submitted the correct syntax for the API call and resubmit the logs if you still have errors.

Ajit
answered a month ago
  • It was my fault that I pasted the old err-log. I already removed the quotes and it still refused to compile. Here is the actual one (I also edited the question and changed the log):

    Traceback (most recent call last): File "app.py", line 7, in <module> bucket_name= ssm.get_parameter(Name= 'dragon_data_bucket_name',WithDecryption='False')['Parmaeter']['value'] #Systems Manager File "/home/ec2-user/.local/lib/python3.7/site-packages/botocore/client.py", line 514, in _api_call return self._make_api_call(operation_name, kwargs) File "/home/ec2-user/.local/lib/python3.7/site-packages/botocore/client.py", line 902, in _make_api_call api_params, operation_model, context=request_context File "/home/ec2-user/.local/lib/python3.7/site-packages/botocore/client.py", line 963, in _convert_to_request_dict api_params, operation_model File "/home/ec2-user/.local/lib/python3.7/site-packages/botocore/validate.py", line 381, in serialize_to_request raise ParamValidationError(report=report.generate_report()) botocore.exceptions.ParamValidationError: Parameter validation failed: Invalid type for parameter WithDecryption, value: False, type: <class 'str'>, valid types: <class 'bool'>

0

Your error log still doesn't match your code, it looks like you're not running the version you think you are? The log mentions 'Parmaeter' whereas your code has 'Parameter'. I'd suggest then that although your code now has the quotes removed from 'False' that you're actually running another version.

answered a month 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