How to install and run the acme.sh inside AWS lambda? - bash

I am interested to run this acme.sh a LetsEncrypt bash client within AWS Lambda to generate a ECDSA wildcard SSL cert.
I read that AWS lambda now supports bash via Layers.
The documentation within AWS Lambda developer guide doesn't really paint a clear picture for me to do this.
So I was wondering if somebody can help make the developer guide clearer for me in this particular context.

This script is a bit heavy for lambda, id suggest trying to use AWS Fargate instead, which lets you spin up dynamic containers, there's a Dockerfile already in the repo, so start from there.

You can run certbot (that is written with python) on AWS Lambda using python runtime to generate wildcard SSL certs using DNS challenge.
You can also check the complete certbot-lambda script that generates certs and exports them to [AWS](AWS Secrets Manager).

Related

Running/Testing an AWS Serverless API written in Terraform

No clear path to do development in a serverless environment.
I have an API Gateway backed by some Lambda functions declared in Terraform. I deploy to the cloud and everything is fine, but how do I go about setting a proper workflow for development? It seems like a struggle to push every small code change to the cloud while developing in order to run your code. Terraform has started getting some support by the SAM framework to run your Lambda functions locally (https://aws.amazon.com/blogs/compute/better-together-aws-sam-cli-and-hashicorp-terraform/), but still no way to simulate a local server and test out your endpoints in Postman for example.
First of all I use serverless plugin instead of terraform, my answer is based on what you provided and what I found around.
From what I understood so far with priovided documentation you are able to run sam CLI with terraform (cf: Chapter Local testing)
You might follow this documentation to invoke local functions.
I recommend to use JSON files to create use cases instead of stdin injection.
First step is to create your payload in json file and to invoke your lambda with the json payload like
sam local invoke "YOUR_LAMBDA_NAME" -e ./path/to/yourjsonfile.json

Is there a way to deploy a terraform file via an AWS lambda function?

As the title suggests I am looking for a way to deploy a terraform file via an AWS lambda function. I would like to deploy this file via a time-based event. This is my first time working with terraform and I cannot seem to find anything pertaining to this specific use case.
I am much more versed in CloudFormation so normally what I would do is use the boto3 library to set up a lambda function that would deploy a CloudFormation stack. Does anyone know how to do this with a terraform file?

How do I use Terraform to add an existing RDS proxy to my AWS Lambda Function?

In the AWS Lambda service's console, there is a Configuration tab called Database proxies, shown here:
However, in the Terraform registry's entry for an AWS Lambda Function, there does not seem to be a place to define this relationship for my lambda. It's easy enough to add manually after I deploy the Lambda, but for obvious reasons this isn't optimal. It seems like using a DB proxy is a common enough use case for serverless architectures that there would be a way to do this with the resources I've referenced.
What am I missing?
EDIT: As of 9 months ago, this feature was not included in the AWS Provider, but I'm unsure of how to search upcoming nightly or perhaps dev releases of Terraform for this feature...
EDIT EDIT (from my comment below): the RDS, its proxy, the roles they use, the lambdas, and the vpc in which they sit all work as expected. if I go to the above screenshot in the lambdas I am deploying, I can Add database proxy just fine using the proxy I deployed with Terraform. There are no issues with the code, nor any errors. The problem is that having to manually add the Database Proxy to each Lambda I deploy defeats the purpose of using Terraform.

Rundeck to run AWS Lambda function

Does anyone have any information on how to run AWS lambda scripts from rundeck? I was looking into doing this to have a central place that certain uses can log into run deck and run the scripts that are relevant to them, as not everyone has aws access.
I found this: https://www.slideshare.net/tetutaro/lambda-and-rundeck-58884982
But I was hoping there might be something more official somewhere and in English :)
A good way to integrate with Lambda is to use AWS CLI on the Rundeck server and call functions using script step or command step on your workflow. Take a look at this.
Also, and similar to this answer, another good way to interact with Lamda is to access it using API (you have two options: using HTTP Workflow Step plugin or via script step on your workflow).
Finally, maybe is a good opportunity to develop some custom plugin focused on AWS Lambda.

How Can I Use AWS Lambda To Run Shell Script On A Specific EC2 Instance?

I'm new to AWS Lambda and following some tutorials to learn. But I haven't figured out if I'm able to run some shell script on EC2 instances via AWS Lambda.
I have multiple servers running on AWS EC2 24/7. Within the EC2 instance, I have a script to generate logs, package it and send it to my email. You can assume there's a shell script written in advance for me to trigger.
So far I always use session manager or ssh into each instance to execute the shell script. However, due to the secruity concerns, I'm not going to ssh anymore. As I need to execute the shell script on each server in a particular order, it's painful to open that much session manager and execute each shell scripts one by one manually.
So I wonder if I can get some help from AWS Lambda. My goal is to use AWS Lambda to ssh (or session manager or something else) to get in the EC2 instance to execute the shell script for me. As I have multiple servers, I learned that I can use scripts in AWS Lambda to do this one by one automatically, which would make things easy like triggering a AWS Lambda button to execute shell scripts in each server one by one in a particular order.
Could anyone please provide me some guidence on the AWS Lambda part or some other guidence if there's a better way in AWS to allow me execute shell scripts in multiple EC2 in a particular order automatically. I would appreciate that!

Resources