官术网_书友最值得收藏!

Creating a Lambda using AWS CLI

Now that we’ve got the CLI set up, we can use it to make our lives much easier. To create a new function, you need to have a folder containing an index.js file with a basic Lambda code in. Navigate into that folder in your terminal and now you can run these commands:

zip ./index.zip *
aws lambda create-function \
--function-name your-function-name \
--runtime nodejs8.10 \
--role your-lambda-role \
--handler index.handler \
--zip-file fileb://index.zip

Switch out the your-lambda-role for the arn of the role that you created earlier. You can find this by going back to the IAM service in AWS and selecting Roles and clicking on your Lambda role:

Find your role ARN

When you run this it will return a JSON blob with some information about your newly created Lambda.

If you edit your index.js code and want to update the Lambda, then there are three commands you need to run:

rm index.zip
zip ./index.zip *

aws lambda update-function-code \
--function-name your-function-name \
--zip-file fileb://index.zip

Using these scripts, you can now write your code locally and deploy it to AWS. This is good but it can be improved, which is what we're going to do next.

主站蜘蛛池模板: 土默特右旗| 平安县| 江安县| 同德县| 三台县| 忻城县| 涡阳县| 河西区| 大渡口区| 丰顺县| 民县| 垦利县| 秦皇岛市| 汉中市| 安阳县| 宜宾市| 浙江省| 富民县| 呼和浩特市| 通海县| 手机| 洛宁县| 望城县| 夹江县| 六枝特区| 启东市| 慈利县| 昆明市| 保靖县| 上思县| 虎林市| 分宜县| 鲁山县| 湖北省| 铜陵市| 乐平市| 虹口区| 新闻| 通江县| 册亨县| 吉水县|