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

Is it possible to deploy a function to multiple regions ? #40

Open
zenati opened this issue Dec 31, 2021 · 17 comments
Open

Is it possible to deploy a function to multiple regions ? #40

zenati opened this issue Dec 31, 2021 · 17 comments

Comments

@zenati
Copy link

zenati commented Dec 31, 2021

Is it possible to deploy a function to multiple regions ? And call that function with a region as argument ? Thanks.

@aarondfrancis
Copy link
Owner

In theory, yes. I'm not sure the follow-on effects throughout the rest of the library though. For example, when you execute a method you'd then need to pass through the region as well.

What is the larger goal you're trying to accomplish? You could always swap out the config stuff at runtime and call the standard commands / methods.

@clarkeash
Copy link
Contributor

This would be really useful, I have a use case where I wanna do an uptime check (API call) from multiple locations.

@aarondfrancis
Copy link
Owner

I'm not sure what resources are region specific vs universal. I know for sure we'd need buckets in each region, which is doable but maybe a pain? I'm not too sure about the IAM stuff though.

I'd could imagine an interface that looks something like:

Sidecar::setRegion('us-east-1')
// Do stuff

Sidecar::setRegion('us-west-1')
// Do stuff

Any thoughts on that?

@clarkeash
Copy link
Contributor

clarkeash commented Jan 6, 2022

It looks like IAM can be restricted to a region so I assume its not restricted by default.

I think an API on the function itself could be better, perhaps similar to how you do the package config.

e.g.

class FooFunction extends LambdaFunction {
    public function region() {
       // could still return a string here for a single region deployment
        return Region::multi(['eu-west-1', 'us-east-1']) // loop over these when deploying functions
            ->default('eu-west-1');
    }
}
FooFunction::execute(); // defaults to eu-west-1
FooFunction::executeInRegion('us-east-1'); // runs on us-east-1

I dont know the internals of sidecar so what I am suggesting may not be reasonable, its just what I had in mind.

@fgilio
Copy link

fgilio commented Jan 6, 2022

This would be really useful, I have a use case where I wanna do an uptime check (API call) from multiple locations.

That sounds like a good use case.

@zenati Mind sharing your use case?

@aarondfrancis
Copy link
Owner

@clarkeash I like that better, that's very clever.

@zenati
Copy link
Author

zenati commented Mar 14, 2022

@fgilio Yes, it's uptime check from multiple locations as well.

@datashaman
Copy link
Contributor

FYI, S3 buckets are not region-bound, they are global in AWS.

@datashaman
Copy link
Contributor

datashaman commented Apr 6, 2022

With docker images, you could deploy to all of them and then use an ENV value (or even a HTTP region query parameter) to point to the docker ImageUri to be used in Sidecar (which has a region embedded in it).

@mauryaratan
Copy link

@fgilio Yes, it's uptime check from multiple locations as well.

@zenati I landed here looking up the same requirement. Curious if you found a working solution?

@hughsaffar
Copy link

@aarondfrancis, if this package is still being actively maintained, and if you are open to the idea of multi-region deployment, I don't mind putting together a pull request to address this. Let me know.

@clarkeash
Copy link
Contributor

I had a quick look at implementing this but I think it will be a fairly big change

@clarkeash
Copy link
Contributor

@hughsaffar did you ever look at this or were you waiting on @aarondfrancis ?
It should be possible but I dont think I understand the codebase/aws enough to make the change

@hughsaffar
Copy link

@clarkeash I was waiting for @aarondfrancis since it will be a big change as you pointed out above. I eventually moved on to a different solution.

@clarkeash
Copy link
Contributor

@hughsaffar what solution did you come up with?

@hughsaffar
Copy link

@hughsaffar what solution did you come up with?

@clarkeash I used Serverless Framework for AWS infra setup and deploying the functions and created my own abstraction over AWS PHP SDK in PHP to invoke the functions. It might sound like an overengineered solution, but it worked fine for me. It allowed me to have a repo for each function and let me to define a Makefile that allows me to deploy to different regions like

deploy: clean build
	sls deploy --region=us-east-1 --verbose
	sls deploy --region=us-west-1 --verbose

@parkourben99
Copy link

parkourben99 commented Sep 23, 2024

I have made a working version of this, deploys/updates and runs on all regions.

Happy to put together a PR if others would be interested.

Defaults to the region in the sidecar conf file

FooFunction::execute();
FooFunction::region('ap-southeast-2')->execute();
class AwsLambdaScrape extends LambdaFunction
{
    public array $regions = [
        'us-east-1',
        'us-east-2',
        'us-west-1',
        'us-west-2',
        ...
    ];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants