PRECONDITION

Today let’s see how to import the paramiko library into AWS Lambda with this errors: from_buffer() cannot return the address of the raw string within a str or unicode or bytearray object and unable to import function etc.

PROCEDURE

For security i use an AWS instances for install the dependency, because there is python 2.7 installed and windows could create problems.

Create an instances with Amazon Linux 2 AMI and an Public IP/Elastic IP. Use ssh to enter in the machine with our private key.

Create and enter in a new directory and follow this instructions:

Copy to Clipboard

Now zip this folder

Copy to Clipboard

and copy this zip in our local pc by scp.

Remember to insert your python file in the zip where you import the python paramiko library.

This is an example to use the paramiko library for get and put a file in two different server by sftp:

Copy to Clipboard

In this other example we save the file downloaded in a S3 bucket and save it by aws cli in the instances (identified by tag):

Copy to Clipboard

Import the zip in the lambda, use python 2.7, specify the name and file of where you import your code:

The policy for the lambda function:

EC2 filtered by tag

Copy to Clipboard

S3

Copy to Clipboard

SSM

Copy to Clipboard

For the role to attach at the instance:

S3

Copy to Clipboard

SSM

Copy to Clipboard

CONCLUSIONS

Let us know if you have solved the problem!

Recent Tweets

For privacy reasons Twitter needs your permission to be loaded.
I Accept