Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for using Pode in Azure Functions and AWS Lambda #264

Closed
Badgerati opened this issue May 29, 2019 · 4 comments · Fixed by #265
Closed

Support for using Pode in Azure Functions and AWS Lambda #264

Badgerati opened this issue May 29, 2019 · 4 comments · Fixed by #265

Comments

@Badgerati
Copy link
Owner

This is to see if it's possible - or even feasible - to host websites/rest-apis in Azure Functions and AWS Lambda, but using Pode for route management.

In both cases, neither Functions or Lambda use the normal HttpResponse; so new server types will be needed, with an option to specify if Pode is running in a serverless context.

Also, Functions/Lambda have the "request" object supplied to them ($TriggerMetadata/$LambdaInput), so the server function will need a parameter to accept adhoc requests objects.

Furthermore, due to the nature of Functions/Lambda, the only functions from Pode that will likely work are:

  • route
  • middleware
  • endware
  • engine
  • serverless (new)
  • nearly all response functions within routes: json, xml, csv, text, file

There are likely others, but timers etc are out.

Will also need a way of adding headers/cookies - as there's no AddHeader/Cookie methods, so will have to use the Headers dictionary directly.

@Badgerati
Copy link
Owner Author

Badgerati commented May 29, 2019

Good news is I got this working with Azure Functions: https://pode-test-af.azurewebsites.net/api/PodeSite
So websites will work, though not ideal due to functions going to sleep, and images are quite slow to load. For REST APIs it seems to be quite quick.

It's still a work in progress, but an idea of the function app run.ps1 for the above:

param($Request, $TriggerMetadata)

server -r $TriggerMetadata -rp '../www' {
    serverless 'azure-functions'
    engine pode

    route get '/api/PodeSite' {
        view 'simple' -Data @{ 'numbers' = @(1, 2, 3); }
    }
}

../www is the root path with the public/views directories. Error pages also work.

@Badgerati
Copy link
Owner Author

Now, I think I managed to get this working for AWS Lambda, but I can't seem to get PowerShell Lambda functions running locally.

Fortunately, there is very little different on the request/response objects between Azure/AWS.

This means a Lambda equivalent to the Functions script above would be:

#Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.509.0'}
#Requires -Modules @{ModuleName='Pode';ModuleVersion='0.0.0'}

server -r $LambdaInput -rp '/tmp/www' {
    serverless 'aws-lambda'
    engine pode

    route get '/PodeSite' {
        view 'simple' -Data @{ 'numbers' = @(1, 2, 3); }
    }
}

Here, /tmp/www could come from an S3 bucket.

@Badgerati
Copy link
Owner Author

When running in a serverless context, the unsupported functions are the following - everything else is supported.

  • Gui
  • Schedule
  • Limit
  • Access
  • Listen
  • Logger
  • Timer
  • Tcp
  • Handler

Functions to look into:

  • Redirect (todo)
  • Session (todo)
  • Attach (maybe?)
  • Flash (if sessions is done)
  • Cookie (todo)
  • Csrf (maybe?)

Sessions are likely all right, if stored externally (or you can have them local if you don't care the data will be wiped often). Flash is possible if sessions are done.

Cookie/Redirect/Attach each require headers.

CSRF I'm unsure about, is likely just possible from the get go.

@Badgerati Badgerati changed the title Support for running Pode in Azure Functions and AWS Lambda Support for using Pode in Azure Functions and AWS Lambda Jun 3, 2019
Badgerati added a commit that referenced this issue Jun 6, 2019
@Badgerati
Copy link
Owner Author

Managed to get all the following functions working:

  • Redirect
  • Session
  • Attach
  • Flash
  • Cookie
  • Csrf

Badgerati added a commit that referenced this issue Jun 6, 2019
Badgerati added a commit that referenced this issue Jun 7, 2019
Badgerati added a commit that referenced this issue Jun 7, 2019
Badgerati added a commit that referenced this issue Jun 8, 2019
@Badgerati Badgerati added this to the 0.31.0 milestone Jun 9, 2019
Badgerati added a commit that referenced this issue Jun 9, 2019
Badgerati added a commit that referenced this issue Jun 9, 2019
Badgerati added a commit that referenced this issue Jun 10, 2019
Resolves #264: Add support for serverless
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant