简体   繁体   中英

Serverless Framework: how to deploy with CloudFormation?

I am new to the serverless framework. Well, at least to the latest version, which depends heavily on CloudFormation.

I installed the framework globally on my computer using:

npm install -g serverless

I then created a service using:

serverless create --template aws-nodejs --path myService

Finally, I ran:

serverless deploy

Everything seems to deploy normally, it shows no error in the terminal. I can see the CloudFormation files in a newly created, dedicated S3 bucket.

However, I cannot find the default hello Lambda function in the AWS Lambda console.

What am I missing? Are the CloudFormation files not supposed to create Lambda functions upon deployment?

The reason the default hello Lambda function is not listed in the AWS Lambda console is because your Lambda function was uploaded to the default region (us-east-1), while the Lambda console displays the functions of another region.

To set the correct region for your functions, you can use the region field of the serverless.yml file.

Make sure the region property is directly under the provider section . With 2/4 spaces indent. Like this:

provider:
    region: eu-west-1

Alternatively, you can specify the region at deployment time, like so:

sls deploy --region eu-west-1

Duh, I had made a super silly mistake:

I did not properly set the AWS region

So, I was looking for a lambda function in the wrong region: of course it could not be found!

Before deploying, one must make sure to set the correct region

UPDATE Well actually, I had set the region in serverless.yml by providing:

region: eu-west-1

However, for some reason the default region was not overwritten, and the function was deployed to the wrong region. Odd, that.

Anyway, one easy way around this issue is to provide the region at deployment time:

sls deploy --region eu-west-1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM