AWS Chalice — Painless Serverless Adventure (2)

Kemalcan Bora
AWS Tip
Published in
3 min readJul 26, 2022

--

In this past article, we wrote something about the Chalice framework. In this article, we will examine topics such as pure lambda and schedule cron.

Painless Serverless Adventure (1)

What is Pure lambda? [1]

If you want to create a function that is not supported by Chalice or just wants to create Lambda functions but manages to process dependencies and deployments yourself if you do not want to use it For example you wrote a search algorithm on Python and you don’t want it to be endpoint and you want another NodeJS lambda to run it here as pure lambda and write NodeJS you can trigger via.

@app.lambda_function(name="SearchMe")
def search(event, context):
return {'hello': 'world'}

You don’t need to name it here, but it’s good to add event, context.

What does context contain here? [2]

  • function_name – Lambda name.
  • function_version – Function version.
  • invoked_function_arn – Amazon Resource Name (ARN) used to call the function. Specifies whether the caller specifies a version number or alias.
  • memory_limit_in_mb – The amount of memory allocated for the function.
  • aws_request_id – Identifier of the request to call.
  • log_group_name – Log groups.
  • log_stream_name – Log flow for function instance.
  • identity – (mobile apps) Information about the Amazon Cognito ID authorizing the request.
  • cognito_identity_id – Authenticated Amazon Cognito ID.
  • cognito_identity_pool_id – Amazon Cognito ID pool.
  • client_context — (mobile applications) The client context provided by the client application to Lambda.
  • client.installation_id
  • client.app_title
  • client.app_version_name
  • client.app_version_code
  • client.app_package_name

Now let’s start the project
The project will be an endpoint that will be quite simple, as soon as we give the youtube link here, it will convert it to MP3 and throw it to S3, maybe we can send an email or something to ourselves in the future. We’ll write our code, but where?

Amazon says that “As your app grows, you can get to a point where you prefer to configure your app in multiple files. You can create a chalicelib/ directory and anything in that directory is internationally included in the distribution package.” [3] We continue, let’s focus first on youtube videos later on other We will focus on other libraries for downloading videos on platforms here is Pytube for youtube I think the most beautiful library.

pip install pytube

After installing, what we have to do is add this to the requirements.txt file.

pytube==12.1.0

I created a python file named downloader and wrote a little code for youtube and maybe other platforms that we would use later, and I added it to chalice lib.

in the next stage, we will deploy to S3 and then delete what we have installed with schedule cron lambda once a week. See you in the other article.

References

--

--