首页 > 解决方案 > AWS V3 教程 - 创建和使用 Lambda 函数

问题描述

我正在试用适用于 Javascript 的 AWS SDK 的第 3 版教程。以下是网址: https ://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/lambda-create-table-example.html

我曾多次尝试按照上述步骤进行操作,但均未成功。

如果有人在 V3 中成功使用了本教程,或者更有经验的人可以尝试让我知道我做错了什么,那将有很大帮助。

我已按照以下步骤操作:

步骤 1. 使用 AWS CloudFormation 创建 AWS 资源

    created describe-stack-resources.js, setup.yaml

    in command prompt->aws cloudformation create-stack --stack-name [STACK_NAME] --template-body file://setup.yaml --capabilities CAPABILITY_IAM

    in command prompt->node describe-stack-resources.js [STACK_NAME]

    noted down IAM_ROLE, IDENTITY_POOL_ID, and BUCKET_NAME

步骤 2. 创建 Html

    created LambdaApp/index.html and uploaded to S3 bucket

步骤 3. 准备浏览器脚本

    created LambdaApp/dynamoClient.js and LambdaApp/lambdaClient.js
    created LamdaApp/index.js with function name = createTable
    in command prompt->webpack LambdaApp/index.js --mode development --target web --devtool eval -o LambdaApp/main.js
    webpack created main.js

步骤 4. 创建 Lambda 函数

    created a file called mylambdafunction.js

    webpacked it to create index.js

    zipped index.js to my-lambda-function.zip.

    Uploaded zip file to S3 bucket

步骤 5. 部署 Lambda 函数

    created lambda-function-setup.js

    in command prompt-> node lambda-function-setup.js

我可以在 AWS 中看到 createTable 函数但是当我运行 html 的 url 时,我得到一个错误 createTable is not defined

标签: amazon-web-servicesamazon-s3aws-lambdaamazon-dynamodb

解决方案


推荐阅读