Boto3 EC2 CreateSnapshots Validation Error with ExcludeDataVolumeIds - amazon-web-services

I am trying to create snapshots with Boto3.
snapshot_response = client.create_snapshots(
Description='super important backup',
InstanceSpecification={
'InstanceId': 'i-something',
'ExcludeBootVolume': True,
'ExcludeDataVolumeIds': ['vol-something1','vol-something2'],
},
CopyTagsFromSource='volume'
)
But if fails with this error.
[ERROR] ParamValidationError: Parameter validation failed:
Unknown parameter in InstanceSpecification: \"ExcludeDataVolumeIds\", must be one of: InstanceId, ExcludeBootVolume
Traceback (most recent call last):
File \"/something/some_dir/some_script.py\", line 50, in some_function
snapshot_response = client.create_snapshots(
File \"/var/runtime/botocore/client.py\", line 391, in _api_call
return self._make_api_call(operation_name, kwargs)
File \"/var/runtime/botocore/client.py\", line 691, in _make_api_call
request_dict = self._convert_to_request_dict(
File \"/var/runtime/botocore/client.py\", line 739, in _convert_to_request_dict
request_dict = self._serializer.serialize_to_request(
File \"/var/runtime/botocore/validate.py\", line 360, in serialize_to_request
raise ParamValidationError(report=report.generate_report())END
Has anyone got this sorted?

Related

using pipreqs getting unknown error while to create requirements.txt

pipreqs .\
the following error is comming. i searched on the google i didn't find any solution.
ERROR: Failed on file: .\static\bower_components\jvectormap\converter\converter.py
Traceback (most recent call last):
File "C:\Users\bsant\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\bsant\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\bsant\Pictures\lms_m16\venv\Scripts\pipreqs.exe_main.py", line 7, in
File "C:\Users\bsant\Pictures\lms_m16\venv\lib\site-packages\pipreqs\pipreqs.py", line 488, in main
init(args)
File "C:\Users\bsant\Pictures\lms_m16\venv\lib\site-packages\pipreqs\pipreqs.py", line 415, in init
candidates = get_all_imports(input_path,
File "C:\Users\bsant\Pictures\lms_m16\venv\lib\site-packages\pipreqs\pipreqs.py", line 131, in get_all_imports
raise exc
File "C:\Users\bsant\Pictures\lms_m16\venv\lib\site-packages\pipreqs\pipreqs.py", line 117, in get_all_imports
tree = ast.parse(contents)
File "C:\Users\bsant\AppData\Local\Programs\Python\Python310\lib\ast.py", line 50, in parse
return compile(source, filename, mode, flags,
File "", line 139
raise Exception, "Wrong geometry type: "+geometryType
^
SyntaxError: invalid syntax

Localstack : Creating stack from cloudformation file which refer to some existing reources

I am trying to deploy a stack using localstack.
My cloudformation file refer to few existing resources which are already created on the dev environment.
While deploying my cloudformation I am getting below errors:
2022-10-03T10:17:26.431 DEBUG --- [ Thread-256] l.u.c.template_deployer : Error applying changes for CloudFormation stack "ashford1": An error occurred (InternalError) when calling the AttachRolePolicy operation (reached max retries: 4): exception while calling iam.AttachRolePolicy: Traceback (most recent call last):
File "/opt/code/localstack/localstack/aws/chain.py", line 90, in handle
handler(self, self.context, response)
File "/opt/code/localstack/localstack/aws/handlers/service.py", line 122, in __call__
handler(chain, context, response)
File "/opt/code/localstack/localstack/aws/handlers/service.py", line 92, in __call__
skeleton_response = self.skeleton.invoke(context)
File "/opt/code/localstack/localstack/aws/skeleton.py", line 153, in invoke
return self.dispatch_request(context, instance)
File "/opt/code/localstack/localstack/aws/skeleton.py", line 165, in dispatch_request
result = handler(context, instance) or {}
File "/opt/code/localstack/localstack/aws/forwarder.py", line 60, in _call
return fallthrough_handler(context, req)
File "/opt/code/localstack/localstack/services/moto.py", line 83, in _proxy_moto
return call_moto(context)
File "/opt/code/localstack/localstack/services/moto.py", line 46, in call_moto
return dispatch_to_backend(context, dispatch_to_moto, include_response_metadata)
File "/opt/code/localstack/localstack/aws/forwarder.py", line 113, in dispatch_to_backend
http_response = http_request_dispatcher(context)
File "/opt/code/localstack/localstack/services/moto.py", line 111, in dispatch_to_moto
status, headers, content = dispatch(request, request.url, request.headers)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 217, in dispatch
return cls()._dispatch(*args, **kwargs)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 356, in _dispatch
return self.call_action()
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 443, in call_action
response = method()
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/iam/responses.py", line 17, in attach_role_policy
self.backend.attach_role_policy(policy_arn, role_name)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/iam/models.py", line 1689, in attach_role_policy
policy = arns[policy_arn]
KeyError: 'arn:aws:iam::XXXXX:policy/BasePolicy-Default-XXX'
Traceback (most recent call last):
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1569, in _run
self.do_apply_changes_in_loop(changes, stack)
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1646, in do_apply_changes_in_loop
self.apply_change(change, stack=stack)
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1723, in apply_change
result = deploy_resource(self, resource_id)
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 853, in deploy_resource
result = execute_resource_action(resource_id, stack, ACTION_CREATE)
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 891, in execute_resource_action
result = func["function"](resource_id, resources, resource_type, func, stack_name)
File "/opt/code/localstack/localstack/services/cloudformation/models/iam.py", line 294, in _post_create
iam.attach_role_policy(RoleName=role_name, PolicyArn=arn)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/botocore/client.py", line 514, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/botocore/client.py", line 938, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InternalError) when calling the AttachRolePolicy operation (reached max retries: 4): exception while calling iam.AttachRolePolicy: Traceback (most recent call last):
File "/opt/code/localstack/localstack/aws/chain.py", line 90, in handle
handler(self, self.context, response)
File "/opt/code/localstack/localstack/aws/handlers/service.py", line 122, in __call__
handler(chain, context, response)
File "/opt/code/localstack/localstack/aws/handlers/service.py", line 92, in __call__
skeleton_response = self.skeleton.invoke(context)
File "/opt/code/localstack/localstack/aws/skeleton.py", line 153, in invoke
return self.dispatch_request(context, instance)
File "/opt/code/localstack/localstack/aws/skeleton.py", line 165, in dispatch_request
result = handler(context, instance) or {}
File "/opt/code/localstack/localstack/aws/forwarder.py", line 60, in _call
return fallthrough_handler(context, req)
File "/opt/code/localstack/localstack/services/moto.py", line 83, in _proxy_moto
return call_moto(context)
File "/opt/code/localstack/localstack/services/moto.py", line 46, in call_moto
return dispatch_to_backend(context, dispatch_to_moto, include_response_metadata)
File "/opt/code/localstack/localstack/aws/forwarder.py", line 113, in dispatch_to_backend
http_response = http_request_dispatcher(context)
File "/opt/code/localstack/localstack/services/moto.py", line 111, in dispatch_to_moto
status, headers, content = dispatch(request, request.url, request.headers)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 217, in dispatch
return cls()._dispatch(*args, **kwargs)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 356, in _dispatch
return self.call_action()
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 443, in call_action
response = method()
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/iam/responses.py", line 17, in attach_role_policy
self.backend.attach_role_policy(policy_arn, role_name)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/iam/models.py", line 1689, in attach_role_policy
policy = arns[policy_arn]
KeyError: 'arn:aws:iam::XXXXXXXXXXXX:policy/Policy-Default-XXXX'
My questions:
Should I create the existing resources manually before deploying the stack?
Can I create the stack with multiple resource files places in cloudformation.d folder? As of now, I need to create a single cloudformation.yml file and use that to deploy stack.
Thanks for your time and help.

how to fix error with ssl certificate in aws lambda

I am using this guide on the AWS deeplens. I am experimenting with the code and at one point it stopped working for the second standalone lambda function. At some point, the code started getting the exception and I only recently noticed it.
Here is the code in question:
def sendMessageToIoTTopic(iotMessage):
# this is a default topic if its not specified in the lambda envirionment
topicName = "worker-safety"
if "iot_topic" in os.environ:
topicName = os.environ['iot_topic']
print("Send message to topic: " + topicName + " before")
iotClient = boto3.client('iot-data', region_name='us-east-1')
response = iotClient.publish(
topic=topicName,
qos=1,
payload=json.dumps(iotMessage)
)
print("Send message to topic: " + topicName + "after")
print("using this topic **{}** response is {}".format(topicName, response))
The guide says to modify the default timeout from 1 second to 3 seconds. Here is the log for this code with a 3 second timeout.
2021-01-31T14:28:35.579-05:00 Before we send to iot MQTT?
2021-01-31T14:28:35.579-05:00 Send message to topic: worker-safety-demo-cloud before
2021-01-31T14:28:36.202-05:00 END RequestId: 89794691-a149-4480-b0bd-fd1a69522774
2021-01-31T14:28:36.202-05:00 REPORT RequestId: 89794691-a149-4480-b0bd-fd1a69522774 Duration: 3003.48 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 35 MB
2021-01-31T14:28:36.202-05:00 2021-01-31T19:28:36.201Z 89794691-a149-4480-b0bd-fd1a69522774 Task timed out after 3.00 seconds
2021-01-31T14:28:38.016-05:00 START RequestId: 71562d34-28d6-471a-8a43-b1e0bab1d621 Version: $LATEST
Adjusting the timeout for the lambda function from 3 seconds to 15 seconds allows us to see the timeout error in detail. It shows that it is an SSL error.
This is the resultant log with more info:
2021-01-31T14:36:08.775-05:00 Before we send to iot MQTT?
2021-01-31T14:36:08.775-05:00 Send message to topic: worker-safety-demo-cloud before
2021-01-31T14:36:17.295-05:00 [ERROR] SSLError: SSL validation failed for https://data.iot.us-east-1.amazonaws.com/topics/worker-safety-demo-cloud?qos=1 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091) Traceback (most recent call last): File "/var/task/lambda_function.py", line 177, in lambda_handler sendMessageToIoTTopic(iotMessage) File "/var/task/lambda_function.py", line 119, in sendMessageToIoTTopic payload=json.dumps(iotMessage) File "/var/runtime/botocore/client.py", line 357, in _api_call return self._make_api_call(operation_name, kwargs) File "/var/runtime/botocore/client.py", line 663, in _make_api_call operation_model, request_dict, request_context) File "/var/runtime/botocore/client.py", line 682, in _make_request return self._endpoint.make_request(operation_model, request_dict) File "/var/runtime/botocore/endpoint.py", line 102, in make_request return self._send_request(request_dict, operation_model) File "/var/runtime/botocore/endpoint.py", line 137, in _send_request success_response, exception): File "/var/runtime/botocore/endpoint.py", line 256, in _needs_retry caught_exception=caught_exception, request_dict=request_dict) File "/var/runtime/botocore/hooks.py", line 356, in emit return self._emitter.emit(aliased_event_name, **kwargs) File "/var/runtime/botocore/hooks.py", line 228, in emit return self._emit(event_name, kwargs) File "/var/runtime/botocore/hooks.py", line 211, in _emit response = handler(**kwargs) File "/var/runtime/botocore/retryhandler.py", line 183, in __call__ if self._checker(attempts, response, caught_exception): File "/var/runtime/botocore/retryhandler.py", line 251, in __call__ caught_exception) File "/var/runtime/botocore/retryhandler.py", line 277, in _should_retry return self._checker(attempt_number, response, caught_exception) File "/var/runtime/botocore/retryhandler.py", line 317, in __call__ caught_exception) File "/var/runtime/botocore/retryhandler.py", line 223, in __call__ attempt_number, caught_exception) File "/var/runtime/botocore/retryhandler.py", line 359, in _check_caught_exception raise caught_exception File "/var/runtime/botocore/endpoint.py", line 200, in _do_get_response http_response = self._send(request) File "/var/runtime/botocore/endpoint.py", line 269, in _send return self.http_session.send(request) File "/var/runtime/botocore/httpsession.py", line 281, in send raise SSLError(endpoint_url=request.url, error=e)
2021-01-31T14:36:17.296-05:00 END RequestId: 0da11ea2-c9d3-42ce-a8d5-cd3e709bf42e
The SSL error in detail is this:
[ERROR] SSLError: SSL validation failed for https://data.iot.us-east-1.amazonaws.com/topics/worker-safety-demo-cloud?qos=1 [SSL: CERTIFICATE_VERIFY_FAILED]
certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)Traceback (most recent call last):  
File "/var/task/lambda_function.py", line 177, in lambda_handler    sendMessageToIoTTopic(iotMessage)  
File "/var/task/lambda_function.py", line 119, in sendMessageToIoTTopic    payload=json.dumps(iotMessage)  
File "/var/runtime/botocore/client.py", line 357, in _api_call    return self._make_api_call(operation_name, kwargs)  
File "/var/runtime/botocore/client.py", line 663, in _make_api_call    operation_model, request_dict, request_context)  
File "/var/runtime/botocore/client.py", line 682, in _make_request    return self._endpoint.make_request(operation_model, request_dict)  
File "/var/runtime/botocore/endpoint.py", line 102, in make_request    return self._send_request(request_dict, operation_model)  
File "/var/runtime/botocore/endpoint.py", line 137, in _send_request    success_response, exception):  
File "/var/runtime/botocore/endpoint.py", line 256, in _needs_retry    caught_exception=caught_exception, request_dict=request_dict)  
File "/var/runtime/botocore/hooks.py", line 356, in emit    return self._emitter.emit(aliased_event_name, **kwargs)  
File "/var/runtime/botocore/hooks.py", line 228, in emit    return self._emit(event_name, kwargs)  
File "/var/runtime/botocore/hooks.py", line 211, in _emit    response = handler(**kwargs)  File "/var/runtime/botocore/retryhandler.py", line 183, in __call__    if self._checker(attempts, response, caught_exception):  
File "/var/runtime/botocore/retryhandler.py", line 251, in __call__    caught_exception)  File "/var/runtime/botocore/retryhandler.py", line 277, in _should_retry    return self._checker(attempt_number, response, caught_exception)  
File "/var/runtime/botocore/retryhandler.py", line 317, in __call__    caught_exception)  File "/var/runtime/botocore/retryhandler.py", line 223, in __call__    attempt_number, caught_exception)  
File "/var/runtime/botocore/retryhandler.py", line 359, in _check_caught_exception    raise caught_exception  
File "/var/runtime/botocore/endpoint.py", line 200, in _do_get_response    http_response = self._send(request)  
File "/var/runtime/botocore/endpoint.py", line 269, in _send    return self.http_session.send(request) 
 File "/var/runtime/botocore/httpsession.py", line 281, in send    raise SSLError(endpoint_url=request.url, error=e)

Django Zappa Lambda Deploy "botocore.errorfactory.ResourceNotFoundException"

I am trying to deploy simple django application from zappa (https://romandc.com/zappa-django-guide/) I am getting the following error. Is there any permission issue or some other issue with the dev setup?
Traceback (most recent call last):
File "e:\personal\envs\py3\lib\site-packages\zappa\cli.py", line 753, in deploy
function_name=self.lambda_name)
File "e:\personal\envs\py3\lib\site-packages\zappa\core.py", line 1286, in get_lambda_function
FunctionName=function_name)
File "e:\personal\envs\py3\lib\site-packages\botocore\client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "e:\personal\envs\py3\lib\site-packages\botocore\client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the GetFunction operation: Function not found: arn:aws:lambda:ap-south-1:122866061462:function:frankie-dev
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "e:\personal\envs\py3\lib\site-packages\zappa\cli.py", line 2778, in handle
sys.exit(cli.handle())
File "e:\personal\envs\py3\lib\site-packages\zappa\cli.py", line 512, in handle
self.dispatch_command(self.command, stage)
File "e:\personal\envs\py3\lib\site-packages\zappa\cli.py", line 549, in dispatch_command
self.deploy(self.vargs['zip'])
File "e:\personal\envs\py3\lib\site-packages\zappa\cli.py", line 786, in deploy
self.lambda_arn = self.zappa.create_lambda_function(**kwargs)
File "e:\personal\envs\py3\lib\site-packages\zappa\core.py", line 1069, in create_lambda_function
response = self.lambda_client.create_function(**kwargs)
File "e:\personal\envs\py3\lib\site-packages\botocore\client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "e:\personal\envs\py3\lib\site-packages\botocore\client.py", line 586, in _make_api_call
api_params, operation_model, context=request_context)
File "e:\personal\envs\py3\lib\site-packages\botocore\client.py", line 641, in _convert_to_request_dict
api_params, operation_model)
File "e:\personal\envs\py3\lib\site-packages\botocore\validate.py", line 291, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "Layers", must be one of: FunctionName, Runtime, Role, Handler, Code, Description, Timeout, MemorySize, Publish, VpcConfig, DeadLetterConfig, Environment, KMSKeyArn, TracingConfig, Tags
I had the exact same error trying to deploy a Flask app using Zappa and then realized that I was using an old botocore package version. I changed all the package versions in my requirements.txt file to the ones on zappa's github page and it fixed the issue for me!

python-selenium on aws lambda throws error when switch_back_to.default_content and try to select element

python-selenium using phantomjs used to open an iFrame inside the page, then after switching back to the default content(driver.switch_to.default_content()) does not work.
The following is a pseudo code snippet to explain the scenario.
frame = WebDriverWait(driver, wait_time).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe.class_name")))
......
driver.switch_to.default_content()
print('Switched back to default content')
# Error occurs when line below is interpreted
driver.find_element_by_css_selector("div[title^='Test %s']" %(array_of_content[1]))
Following error occurs:-
Traceback (most recent call last):
File "/var/task/main.py", line 217, in test_method
driver.find_element_by_css_selector("div[title^='Test %s']" %(array_of_content[1]))
File "/var/task/selenium/webdriver/support/wait.py", line 71, in until
value = method(self._driver)
File "/var/task/selenium/webdriver/support/expected_conditions.py", line 213, in __call__
element = visibility_of_element_located(self.locator)(driver)
File "/var/task/selenium/webdriver/support/expected_conditions.py", line 78, in __call__
return _element_if_visible(_find_element(driver, self.locator))
File "/var/task/selenium/webdriver/support/expected_conditions.py", line 307, in _find_element
return driver.find_element(*by)
File "/var/task/selenium/webdriver/remote/webdriver.py", line 752, in find_element
'value': value})['value']
File "/var/task/selenium/webdriver/remote/webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "/var/task/selenium/webdriver/remote/remote_connection.py", line 401, in execute
return self._request(command_info[0], url, body=data)
File "/var/task/selenium/webdriver/remote/remote_connection.py", line 471, in _request
resp = opener.open(request, timeout=self._timeout)
File "/usr/lib64/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/usr/lib64/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 1229, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib64/python2.7/urllib2.py", line 1202, in do_open
r = h.getresponse(buffering=True)
File "/var/task/raven/breadcrumbs.py", line 328, in getresponse
rv = real_getresponse(self, *args, **kwargs)
File "/usr/lib64/python2.7/httplib.py", line 1132, in getresponse
response.begin()
File "/usr/lib64/python2.7/httplib.py", line 453, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python2.7/httplib.py", line 417, in _read_status
raise BadStatusLine(line)
BadStatusLine: ''
Any ideas, what is happening.
As I am able to see the same error, even if I write driver.save_screenshot('test.png').
But it is not throwing any error on local machines, also tried to use AMI instance to replicate if something is there in concern Amazon Linux.