(28) section intro (29) CloudWatch logs (30) using AWS SDK
(30) using AWS SDK
npm i aws-sdk
services/node-lambda/hello.ts
import {S3} from "aws-sdk";
const s3Client = new S3()
...
const buckets = await s3Client.listBuckets().promise();
...
body: 'here are your buckets' + JSON.stringify(buckets.Buckets)
infra/SpaceStack.ts
const s3PolicyStatement = new PolicyStatement();
s3PolicyStatement.addActions('s3:ListAllMyBuckets');
s3PolicyStatement.addResources('*'); // anti-pattern ; use specific!
helloLambdaNodeJs.addToRolePolicy(s3PolicyStatement);
(31) run lambda locally in debug mode run config (in VSCode)
{
"version": "0.2.0",
"configurations":[
{
"type": "node"
"request": "launch"
"name":"Debug local file",
"runtimeArgs":["-r", "ts-node/register"]
"args":"${relativeFile}"
"env":{"AWS_REGION":"eu-west-2"}
}
]
}
(you can add AWS credentials to env if you’re not logged in locally)
Run lambda/api-gateway locally from command line > cdk run local lambda with sam-cli Debug with 1password-credentials from intellij > Debug typescript file with breakpoints (credentials via 1password)