Skip to content

Commit faad1cb

Browse files
committed
WIP on CDK code for Lambda in Rust
1 parent 4afad24 commit faad1cb

23 files changed

+650
-0
lines changed

cdk/rust_example_lambda/.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@echo off
2+
3+
if "%1"=="" goto noargs
4+
5+
aws lambda invoke --function-name %1 --payload file://dynamodb-payload.json output
6+
goto end
7+
8+
:noargs
9+
echo You must supply the name of a Lambda function
10+
11+
:end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if [ "$1" == "" ]
4+
then
5+
echo You must supply the name of a Lambda function
6+
else
7+
aws lambda invoke --function-name $1 --payload file://dynamodb-payload.json output
8+
fi

cdk/rust_example_lambda/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Amazon Lambda function code examples in Go
2+
3+
This code example uses the
4+
[AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html)
5+
to create the following resources:
6+
7+
- An Amazon S3 bucket
8+
- An Amazon DynamoDB table
9+
- An Amazon SNS topic
10+
- An Amazon SQS queue
11+
12+
In addition, this project creates AWS Lambda functions,
13+
in Go, to detect the following events:
14+
15+
- An object uploaded to the Amazon S3 bucket
16+
- An item added to the Amazon DynamoDB table
17+
- A message sent to the Amazon SNS topic
18+
- A message sent to the Amazon SQS queue
19+
20+
The go functions are in their respective sub-folders in **src**.
21+
22+
## Using this code
23+
24+
Copy the contents of this directory to your computer.
25+
If you want to change CloudFormation stack name from the
26+
current value **GoLambdaCdkStack**,
27+
change that value in **cdk.json**, **bin/go-lambda-cdk.ts** and **lib/go-lambda-cdk-stack.ts**
28+
to the value you prefer.
29+
30+
You must run the following command to get the packages
31+
that this CDK app requires:
32+
33+
`npm install`
34+
35+
You'll know you have all of the packages you need
36+
if you can successfully execute the following command
37+
to create a CloudFormation stack from this CDK app:
38+
39+
`cdk synth`
40+
41+
This creates the template **GoLambdaCdkStack.template.json**
42+
(unless you've changed the stack name) in **cdk.out**.
43+
44+
If you encounter any errors running CDK commands,
45+
see the
46+
[Troubleshooting common AWS CDK issues](https://docs.aws.amazon.com/cdk/latest/guide/troubleshooting.html#troubleshooting_toolkit)
47+
topic in the CDK developer guide.
48+
49+
## Working with the CDK app
50+
51+
If you aren't familiar with the CDK, here are some common commands:
52+
53+
- `cdk deploy` deploy this stack to your default AWS account/region
54+
- `cdk diff` compare deployed stack with current state
55+
- `cdk ls` lists your CloudFormation stacks
56+
- `cdk synth` create a CloudFormation template in
57+
58+
See [CDK command](https://docs.aws.amazon.com/cdk/latest/guide/cli.html)
59+
topic in the CDK developer guide for details.
60+
61+
## Getting information about the new resources
62+
63+
Once you deploy the application, it display the following information
64+
that you can use to work with the created resources:
65+
66+
- The name of the resource
67+
- The name of the Lambda function that handles the events from the resource
68+
- The name of the Amazon CloudWatch log group to which
69+
print statements from the AWS Lambda function are sent
70+
71+
You can use the CLI to get information about the resources created by
72+
the resulting CloudFormation template by running the following command,
73+
where *STACK-NAME* is the name of your CloudFormation stack:
74+
75+
`aws cloudformation describe-stacks --stack-name STACK-NAME --query Stacks[0].Outputs --output text`
76+
77+
## Testing the notifications
78+
79+
This project contains the following Windows batch and Bash script files that you can use
80+
to test the AWS Lambda functions by sending a JSON payload to the function specified on the command line:
81+
82+
- **DynamoDBRecord.bat**, **DynamoDBRecord.sh**: these scripts send the data in **dynamodb-payload.json**.
83+
- **S3Record.bat**, **S3Record.sh**: these scripts send the data in **s3-payload.json**.
84+
- **SNSRecord.bat**, **SNSRecord.sh**: these scripts send the data in **sns-payload.json**.
85+
- **SQSRecord.sh**, **SQSRecord.bat**: these scripts send the data in **sqs-payload.json**.

cdk/rust_example_lambda/S3Record.bat

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@echo off
2+
3+
if "%1"=="" goto noargs
4+
5+
aws lambda invoke --function-name %1 --payload file://s3-payload.json output
6+
goto end
7+
8+
:noargs
9+
echo You must supply the name of a Lambda function
10+
11+
:end

cdk/rust_example_lambda/S3Record.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if [ "$1" == "" ]
4+
then
5+
echo You must supply the name of a Lambda function
6+
else
7+
aws lambda invoke --function-name $1 --payload file://s3-payload.json output
8+
fi

cdk/rust_example_lambda/SNSRecord.bat

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@echo off
2+
3+
if "%1"=="" goto noargs
4+
5+
aws lambda invoke --function-name %1 --payload file://sns-payload.json output
6+
goto end
7+
8+
:noargs
9+
echo You must supply the name of a Lambda function
10+
11+
:end

cdk/rust_example_lambda/SNSRecord.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if [ "$1" == "" ]
4+
then
5+
echo You must supply the name of a Lambda function
6+
else
7+
aws lambda invoke --function-name $1 --payload file://sns-payload.json output
8+
fi

cdk/rust_example_lambda/SQSRecord.bat

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@echo off
2+
3+
if "%1"=="" goto noargs
4+
5+
aws lambda invoke --function-name %1 --payload file://sqs-payload.json output
6+
goto end
7+
8+
:noargs
9+
echo You must supply the name of a Lambda function
10+
11+
:end

cdk/rust_example_lambda/SQSRecord.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if [ "$1" == "" ]
4+
then
5+
echo You must supply the name of a Lambda function
6+
else
7+
aws lambda invoke --function-name $1 --payload file://sqs-payload.json output
8+
fi

0 commit comments

Comments
 (0)