Is it possible to use stackset to deploy lambda function to different region?

0

My goal : use stackset to deploy lambda function to mutiple regions, with codepipieline to achieve auto-deploy

I have gave a try before, but failed... The tool I am using are

  • aws stack set
  • aws s3 bucket
  • aws codepipeline
  • aws couldformation

My source code are all store in ap-northeast-1 S3 bucket

Error encountered during the Code deploy propcess "ResourceLogicalId:DBShutDownFunction, ResourceType:AWS::Lambda::Function, ResourceStatusReason:Resource handler returned message: "Error occurred while GetObject. S3 Error Code: PermanentRedirect. S3 Error Message: The bucket is in this region: ap-northeast-1. Please use this region to retry the reques"

Currently, I am very confused if this can be achieved. Since I found out that if I want to deploy lambda function via cloudformation template.yaml, the source code must stored as same as the cloudformation located. (Corret me if I am wrong).

Question 1: does this mean I can't using only one s3 bucket to store the artifact for mutiple regions? So for each region, I have to prepare one S3 bucket for cloudformation in that region to fetch the source ode ?

Question 2: if above ( each region need a distinct s3 bucket for storing source code )is true, should I create the s3 bucket in each region in advance before I start create my code pipeline and cloudformation template.yaml? or do I create s3 bucket in the template.yaml with the lambda function?

RECJ
asked 7 months ago545 views
2 Answers
0
Accepted Answer

Hello.

Question 1: Can I use only one S3 bucket to store artifacts for multiple regions, or do I need a distinct S3 bucket for each region?

You are correct that Lambda functions and other AWS resources are region-specific. When you create a Lambda function, it is created in a specific AWS region, and it expects its associated artifacts (code) to be in the same region. This is why you're encountering the error when trying to deploy Lambda functions to different regions using the same S3 bucket.

To solve this, you generally need to have a separate S3 bucket for each region where you want to deploy Lambda functions or other resources. Each S3 bucket should contain the artifacts (code) for the corresponding region's resources. This ensures that the Lambda functions can access their code without cross-region issues.

Question 2: When should I create the S3 buckets for each region?

You should create the S3 buckets in each region in advance before setting up your CodePipeline and CloudFormation templates. This ensures that the S3 buckets are available for use when needed and that they are in the correct regions.

Best regards, Andrii

profile picture
EXPERT
answered 7 months ago
profile picture
EXPERT
reviewed a month ago
  • Hi Andrii,

    Thanks for the advice. Very clear, if this is the case, I have the follow up questions

    Question 1, If I create the S3 bucket in advance either using AWS CLI or AWS console, since it is not defined in cloudformation tamplate, If one day, I decide no longer to deploy the lambda in that region, other than delete the cloudformation stack itself, do I also have to manually delete the s3 bucket? or is there any way that I can delete the stack with the s3 bucket in the meantime ?

    Question 2, based on my use case, should I still use AWS stackset? since I found out I can't select which atirfact bucket to use for which specific region during setting up the codepipeline.

0

So, if you create S3 buckets outside of CloudFormation and they are not being managed by any CloudFormation stacks, you should manually delete them if they are no longer needed. Be cautious when deleting S3 buckets, as they may contain valuable data.

Stackset is a good idea. Best regards, Andrii

profile picture
EXPERT
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions