MIike Eps
MIike Eps

Reputation: 441

sam deploy failing with error The bucket is in this region: us-east-2. Please use this region to us-east-2

I am new to sam.

I am running aws-cli/2.1.37 Python/3.8.8 Darwin/19.6.0 exe/x86_64 prompt/off

SAM CLI, version 1.29.0

See below the template.yaml file

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  Trikle

  Sample SAM Template for Trikle

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 60

Resources:
  PutProfileFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: PutProfile
      Description: Created With SAM Framework adds users profiles
      Role: arn:aws:iam::630589988206:role/lambdaAllQueryExecutionAllAccessRole
      CodeUri: src/
      Handler: add_profile.lambda_handler
      Runtime: python3.7
      Events:
        PutProfile:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /PutProfile
            Method: post

Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
  PutProfileApi:
    Description: "API Gateway endpoint URL for Prod stage for PutProfile function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/dev/PutProfile/"
  PutProfileFunction:
    Description: "Created With SAM Framework adds users profiles Lambda Function ARN"
    Value: !GetAtt PutProfileFunction.Arn

Trying to deploy lambda function and api gateway to was cloud formation using SAM framework First I ran the command "sam package" and the project was deployed to my was s3 bucket successfully. But after running "sam deploy" it fails. It's failing with error The bucket is in this region: us-east-2. Please use this region to us-east-2

See full stack trace of the error below after issuing the command sam deploy --template-file deploy.yaml --stack-name myStack4

        Deploying with following values
        ===============================
        Stack name                   : mikeStack4
        Region                       : None
        Confirm changeset            : False
        Deployment s3 bucket         : None
        Capabilities                 : null
        Parameter overrides          : {}
        Signing Profiles             : {}

Initiating deployment
=====================

Waiting for changeset to be created..

CloudFormation stack changeset
-------------------------------------------------------------------------------------------------------------------------
Operation                      LogicalResourceId              ResourceType                   Replacement                  
-------------------------------------------------------------------------------------------------------------------------
+ Add                          PutProfileFunctionPutProfile   AWS::Lambda::Permission        N/A                          
                               PermissionProd                                                                             
+ Add                          PutProfileFunction             AWS::Lambda::Function          N/A                          
+ Add                          ServerlessRestApiDeployment7   AWS::ApiGateway::Deployment    N/A                          
                               5e148f6d0                                                                                  
+ Add                          ServerlessRestApiProdStage     AWS::ApiGateway::Stage         N/A                          
+ Add                          ServerlessRestApi              AWS::ApiGateway::RestApi       N/A                          
-------------------------------------------------------------------------------------------------------------------------

Changeset created successfully. arn:aws:cloudformation:us-west-2:630589988206:changeSet/samcli-deploy1630606751/c1aa856f-4259-4a2d-a4cc-c6a738fb1865


2021-09-02 19:19:19 - Waiting for stack create/update to complete

CloudFormation events from changeset
-------------------------------------------------------------------------------------------------------------------------
ResourceStatus                 ResourceType                   LogicalResourceId              ResourceStatusReason         
-------------------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS             AWS::Lambda::Function          PutProfileFunction             -                            
CREATE_IN_PROGRESS             AWS::Lambda::Function          PutProfileFunction             Resource creation Initiated  
ROLLBACK_IN_PROGRESS           AWS::CloudFormation::Stack     mikeStack4                     The following resource(s)    
                                                                                             failed to create:            
                                                                                             [PutProfileFunction].        
                                                                                             Rollback requested by user.  
CREATE_FAILED                  AWS::Lambda::Function          PutProfileFunction             Resource handler returned    
                                                                                             message: "Error occurred     
                                                                                             while GetObject. S3 Error    
                                                                                             Code: PermanentRedirect. S3  
                                                                                             Error Message: The bucket is 
                                                                                             in this region: us-east-2.   
                                                                                             Please use this region to    
                                                                                             retry the request (Service:  
                                                                                             Lambda, Status Code: 400,    
                                                                                             Request ID: 9edeeae4-ecd4-4d 
                                                                                             58-baec-7bef421657e3,        
                                                                                             Extended Request ID: null)"  
                                                                                             (RequestToken: 1238ab0d-1fc9 
                                                                                             -4f8f-9965-4f41d71e5804,     
                                                                                             HandlerErrorCode:            
                                                                                             InvalidRequest)              
DELETE_IN_PROGRESS             AWS::Lambda::Function          PutProfileFunction             -                            
ROLLBACK_COMPLETE              AWS::CloudFormation::Stack     mikeStack4                     -                            
DELETE_COMPLETE                AWS::Lambda::Function          PutProfileFunction             -                            
-------------------------------------------------------------------------------------------------------------------------
Error: Failed to create/update the stack: mikeStack4, Waiter StackCreateComplete failed: Waiter encountered a terminal failure state: For expression "Stacks[].StackStatus" we matched expected path: "ROLLBACK_COMPLETE" at least once

Upvotes: 1

Views: 884

Answers (1)

MIike Eps
MIike Eps

Reputation: 441

The issue was with the region in my AWS CLI configuration

I ran the command AWS configure and reset the region to the suggested one

and the deployment was successful

Upvotes: 2

Related Questions