Amazon Web Services (AWS) is the world’s biggest cloud provider, pioneering the implementation of cloud services like infrastructure-as-a-service (IaaS) and function-as-a-Service (FaaS). But how does Perl fit into the world of AWS?
IaaS is the provisioning of virtualized computing resources. In the case of AWS, the most fundamental IaaS resource is the Amazon Elastic Compute Cloud (EC2), it provides generic computer virtualization. When using EC2 you will boot an Amazon Machine Image (AMI) to create a running machine, called an instance. Amazon maintains an AMI called Amazon Linux 2, it does not have Perl installed, however installing Perl is straightforward. You can even create your own AMI with a pre-installed Perl.
FaaS is the provisioning of a well-defined execution environment, where you can run and manage application functionality, without having to think about infrastructure. The AWS FaaS offering is called AWS Lambda. AWS Lambda natively supports code written in Java, Go, PowerShell, Node.js, C#, Python, and Ruby. However, it also provides an HTTP API for custom runtimes, making it possible to write AWS Lambdas in any programming language, including Perl, if you define a corresponding runtime.
In this talk I will
* give a very short introduction to cloud in general
* introduce a few AWS resources (CloudFormation, EC2, S3, Lambda)
* demonstrate running Perl on an EC2 instance
* demonstrate using AWS::Lambda to create a Perl runtime for AWS Lambda
This talk is a quick introduction to AWS for Perl developers. Attendees need no previous experience with AWS; however, a basic knowledge Perl will be expected.
2. Introduction
In this talk I will
● give a very short introduction to cloud computing in general
● introduce a few AWS resources (CloudFormation, EC2, S3, Lambda)
● demonstrate running Perl on an EC2 instance
● demonstrate using AWS::Lambda to create a Perl runtime for AWS Lambda
2
3. But, first
About me:
● My name is Søren Lund and I’m from Denmark
● I’ve been a SW developer for more than twenty years
● I’ve used many programming languages (C/C++, Perl, Java, JavaScript, …)
● I’ve also worked a lot with build automation, CI/CD and automated tests
● I’ve worked as a AWS consultant for the last couple of years
3
4. Disclaimer
● I’ve no experience running Perl on AWS!
However,
● I know Perl
● I know AWS
Or, as the meme goes
● “Trust Me, I’m an Engineer”
4
6. Cloud Computing
“Cloud computing is the on-demand availability of computer system
resources, especially data storage and computing power, without direct active
management by the user.”
“Cloud computing was popularized with Amazon.com releasing its Elastic
Compute Cloud product in 2006.”
From https://en.wikipedia.org/wiki/Cloud_computing
6
7. Service Models
● Infrastructure as a service (IaaS)
● Platform as a service (PaaS)
● Software as a service (SaaS)
● Serverless computing
● Function as a service (FaaS)
7
8. Infrastructure as a service (IaaS)
“...online services that provide high-level APIs used to dereference various low-
level details of underlying network infrastructure like physical computing
resources, location, data partitioning, scaling, security, backup etc.”
From https://en.wikipedia.org/wiki/Infrastructure_as_a_service
8
9. Function as a service (FaaS)
“...category of cloud computing services that provides a platform allowing
customers to develop, run, and manage application functionalities without the
complexity of building and maintaining the infrastructure typically associated with
developing and launching an app.”
From https://en.wikipedia.org/wiki/Function_as_a_service
9
11. Amazon Web Service (AWS)
● From 2000 to 2005 Amazon.com works on infrastructure
● AWS is launched on March 19 2006, first service is Amazon S3 (Simple
Storage Service)
● Amazon SQS (Simple Queue Service) follows on July 13
● And on August 25 Amazon EC2 (Elastic Compute Cloud) is launched
From https://en.wikipedia.org/wiki/Timeline_of_Amazon_Web_Services
11
12. AWS now has many more services
“...137 top level services spread across 23 categories… many of these top level
services further expand into multiple sub services” (January 2019)
From https://www.quora.com/How-many-AWS-services-are-there
See https://aws.amazon.com/products/
12
13. Getting started with AWS
Sign up at https://aws.amazon.com/
Free tier: https://aws.amazon.com/free/
● Always free - e.g. 1 million free requests on AWS Lambda every month
● 12 month free - e.g. 750 hours EC2 t2.micro instance usage every month
● Trials - e.g. 250 device minutes on AWS Device Farm
13
14. AWS Management Console
From the “Console” you can create/modify/maintain/destroy resources.
See https://console.aws.amazon.com/console/home
14
16. AWS CLI
The AWS CLI is a uber command “aws”, that can be used to manage your AWS
resources and services.
● Written in Python (pip install awscli)
● Enables you to write scripts that creates/modifies/maintains/destroys
resources
● You need to create credentials (tokens) in the Console to use the CLI
See https://aws.amazon.com/cli/
16
17. AWS SDKs
Official SDKs providing APIs for AWS services are available in
● JavaScript
● Python
● PHP
● .NET
● Ruby
● Java
● Go
● Node.js
● C++
See https://aws.amazon.com/tools/
Image by Jonny
Lindner from Pixabay
?
17
18. Paws
● Perl SDK for AWS
● Built by automatically converting Python code into Perl code
● Also includes CLI (paws)
● https://metacpan.org/pod/Paws
18
Image by Jonny
Lindner from Pixabay
❤
19. AWS CloudFormation
● Infrastructure as code
● Define resources in templates (JSON or YAML) or visual designer
● Deploy template using CloudFormation using the Consol, CLI or API
● A deployed template is called a Stack
19
20. Basic Anatomy of a CloudFormation Template
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "",
"Parameters" : { },
"Resources" : { },
"Outputs" : { }
}
See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html
20
22. Creating a CloudFormation Templates
AWS has lots of examples and snippets.
● Examples: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-sample-templates.html
● Snippets: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/CHAP_TemplateQuickRef.html
There’s also a linter for CloudFormation Templates:
● See https://github.com/aws-cloudformation/cfn-python-lint
22
23. Amazon EC2
● EC2 provides generic computer virtualization
● When using EC2 you will boot an Amazon Machine Image (AMI) to create a
running machine, called an instance
● Amazon maintains an AMI called Amazon Linux based on CentOS
○ version 1 has Perl 5.16.3
○ version 2 has no Perl
● Run it locally: docker run -it amazonlinux bash
23
24. User Data in EC2 CloudFormation templates
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"", [
"#!/bin/bashn",
"curl -L http://cpanmin.us | perl - --self-upgraden",
"cpanm Acme::Be::Modernn"
]]
}
}
24
25. Demo time
Code is available on GitHub.
See https://github.com/soren/perl-and-aws
25
27. AWS Lambda
“...an event-driven, serverless computing platform provided by Amazon as a part
of the Amazon Web Services. It is a computing service that runs code in response
to events and automatically manages the computing resources required by that
code. It was introduced in November 2014.”
From https://en.wikipedia.org/wiki/AWS_Lambda
27
28. Console demo
28
Using the AWS Lambda runtime provided by
● https://metacpan.org/pod/AWS::Lambda
To execute the following:
sub handle {
my ($payload, $context) = @_;
my $result = encode_json("Hello from Perl!");
return +{ statusCode => 200, body => $result };
}