Categories
Learning

Async Python Handlers in AWS Lambda

Context

I am creating my first AWS Lambda function in Python from scratch. My function contains async functions, so I declared my handler with the async keyword. But when I deployed and smoke tested in AWS, I received the following error:

{
"errorMessage": "Unable to marshal response: Object of type coroutine is not JSON serializable",
"errorType": "Runtime.MarshalError"
}

Search terms

aws lambda python async handler

Helpful link

https://stackoverflow.com/questions/60455830/can-you-have-an-async-handler-in-lambda-python-3-6

Outcome

Apparently AWS Lambda does not support async handler functions in Python. So you are required to call your asynchronous code from a synchronous handler function using this line of code:

asyncio.get_event_loop().run_until_complete(your_async_handler())

Categories
Learning

Constructing Javascript Objects

Context

I am building a simple model class in Typescript/Javascript and was wondering if there was a shorthand way to avoid having to explicitly set each property name based on the constructor arguments.

Search terms

javascript constructor properties shorthand

Helpful link

https://maksimivanov.com/posts/typescript-constructor-shorthand/

Outcome

I found exactly what I was looking for. This is a Typescript feature only, so it wouldn’t work in pure Javascript, but it is much easier to type:

class Something {
  constructor(public prop1: string, public prop2: string) {}
}

than to type:

class Something {
  public prop1: string;
  public prop2: string;
  constructor(prop1: string, prop2: string) {
    this.prop1 = prop1;
    this.prop2 = prop2;
  }
}

Both produce the same Javascript in the end.

Categories
Learning

Creating Subfolders

Context

I need to provide instructions in a project on which folders and subfolders need to exist before the code will run locally. The required folder is three levels deep, and I want a quick way to create the full directory tree.

Search terms

mkdir subfolders

Helpful link

https://stackoverflow.com/questions/9242163/bash-mkdir-and-subfolders

Outcome

I learned that the mkdir command in a bash terminal includes option “-p” to create all necessary parent folders for a full path in one command.

Categories
Learning

Table metadata in Oracle

Context

Normally I work in SQL Server when I am dealing with relational data but on my current project one of our primary systems uses Oracle as its back end. In order to quickly generate a list of column names for use in an access request, I need to interrogate the table metadata and I cannot recall the way to do this on Oracle.

Search terms

oracle column list query

Helpful link

https://dataedo.com/kb/query/oracle/list-columns-names-in-specific-table

Outcome

I was reminded to use sys.all_tab_columns to get this information.

Categories
Learning

Multidomain SSL Certificates

Context

As I relaunch my website and blog, I want to make it secure. But I host two different domains on this same site (with a host-based redirect), so I wanted to make sure I could secure both of them. My host’s support team told me I would need to use their “Certificate Signing Request” (CSR) to install an SSL cert but this requires a single common name for the domain name. My question was – how do I generate a CSR for multiple domains?

Search terms

csr for multidomain certificate

Helpful link

https://www.namecheap.com/support/knowledgebase/article.aspx/9840/67/how-do-i-activate-a-multidomain-ssl-certificate

Outcome

According to this article, I can use my primary domain in the CSR and add additional domains (SANs) when activating the certificate.

Categories
Learning

Contact form on wordpress

Context

I am attempting to get the contact form working on this site, so I can feel comfortable launching it. For some reason when I test the form, it is showing “There was an error trying to send your message. Please try again later.”

Search terms

wordpress email server

Helpful link

https://www.wpbeginner.com/wp-tutorials/how-to-use-smtp-server-to-send-wordpress-emails/

Outcome

I installed WP Mail SMTP plugin and configured it with the mail server settings from my web hosting provider (winhost.com). I ended up looking also at https://blog.winhost.com/how-to-configure-wordpress-to-use-smtp-on-winhost/ which basically had the same instructions, except that it included specific details for winhost. I also realized that my email password was not very secure, so I generated a new one and updated it on both of my wordpress sites.