Code Monkey home page Code Monkey logo

pulumi-on-aws-lambda's Introduction

pulumi-on-aws-lambda

Minimal Pulumi program that showcases the use of Pulumi Automation API from within an AWS Lambda function.

Background for this showcase is detailed here: https://justedagain.com/posts/2022/pulumi-on-aws-lambda/

The program provisions the following AWS resources:

  • ECR repository for hosting lambda docker container images
  • Lambda function accessible via a function url.
    • Deployed as a docker container image, with Pulumi CLI installed
    • The lambda handler can run a Pulumi inline program which provisions an S3 static site. A unique Pulumi stack is used for provisioning the S3 static site.

Prerequisites

Note: this project assumes the use of a self-managed backend. To set up such a backend see this blogpost and this Github Project.

Deploy

Ensure that the PULUMI_BACKEND_URL and PULUMI_SECRETS_PROVIDER environment variables are set before proceeding.

pulumi stack init pulumi-on-aws-lambda.dev --secrets-provider=$PULUMI_SECRETS_PROVIDER
pulumi config set aws:region eu-central-1

# Deploy pulumi stack
pulumi up --diff

# Once deployment is complete, lambda function URL can be accessed like this
pulumi stack output url

Once deployment is complete, a POST request can be sent to the lambda function url for creating a static website. It is safe to invoke this lambda in parallel (as long as the name parameter is unique) for creation of multiple static websites hosted on S3.

# Invoke lambda via function url to create a static website
$ curl --location --request POST $(pulumi stack output url) --header 'Content-Type: application/json' --data-raw '{"operation": "create","name": "hello","index_content": "hello world"}' 
{"status": "created", "website_url": "s3-website-bucket-xxxxx.s3-website.eu-central-1.amazonaws.com"}%                         

# Access static website
$ curl s3-website-bucket-xxxxx.s3-website.eu-central-1.amazonaws.com
hello world%

# Invoke lambda via function url to destroy static website
$ curl --location --request POST $(pulumi stack output url) --header 'Content-Type: application/json' --data-raw '{"operation": "destroy","name": "hello"}' 
{"status": "destroyed"}%                                                                                                         

pulumi-on-aws-lambda's People

Contributors

mdrbhatti avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.