sidecar icon indicating copy to clipboard operation
sidecar copied to clipboard

Is it possible to deploy a function to multiple regions ?

Open zenati opened this issue 3 years ago • 17 comments

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

zenati avatar Dec 31 '21 19:12 zenati

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.

aarondfrancis avatar Jan 02 '22 17:01 aarondfrancis

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

clarkeash avatar Jan 06 '22 15:01 clarkeash

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?

aarondfrancis avatar Jan 06 '22 16:01 aarondfrancis

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.

clarkeash avatar Jan 06 '22 17:01 clarkeash

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?

fgilio avatar Jan 06 '22 18:01 fgilio

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

aarondfrancis avatar Jan 06 '22 19:01 aarondfrancis

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

zenati avatar Mar 14 '22 13:03 zenati

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

datashaman avatar Apr 06 '22 09:04 datashaman

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).

datashaman avatar Apr 06 '22 09:04 datashaman

@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?

mauryaratan avatar Jun 27 '22 13:06 mauryaratan

@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.

hughsaffar avatar Nov 16 '23 00:11 hughsaffar

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

clarkeash avatar Feb 03 '24 13:02 clarkeash

@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

clarkeash avatar Feb 10 '24 16:02 clarkeash

@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.

hughsaffar avatar Feb 10 '24 17:02 hughsaffar

@hughsaffar what solution did you come up with?

clarkeash avatar Feb 10 '24 17:02 clarkeash

@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

hughsaffar avatar Feb 10 '24 18:02 hughsaffar