Skip to content

Commit f503ecc

Browse files
authored
Merge pull request #398 from dmitchsplunk/main
additional fixes for the lambda workshop
2 parents 91fcc61 + f41db30 commit f503ecc

File tree

7 files changed

+99
-86
lines changed

7 files changed

+99
-86
lines changed

content/en/ninja-workshops/6-lambda-kinesis/1-setup.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ The Workshop Directory `lambda` is a repository that contains all the configurat
7979
### AWS & Terraform Variables
8080

8181
#### AWS
82+
83+
> Note to the workshop instructor: create a new user in the target AWS account called `lambda-workshop-user`.
84+
> Ensure it has full permissions to perform the required actions via Terraform. Create an access token for the `lambda-workshop-user`
85+
> user and share the Access Key ID and Secret Access Key with the workshop participants. Delete the user
86+
> when the workshop is complete.
87+
8288
The AWS CLI requires that you have credentials to be able to access and manage resources deployed by their services. Both Terraform and the Python scripts in this workshop require these variables to perform their tasks.
8389

8490
- Configure the **awscli** with the _**access key ID**_, _**secret access key**_ and _**region**_ for this workshop:
@@ -98,10 +104,24 @@ The AWS CLI requires that you have credentials to be able to access and manage r
98104
aws configure
99105
```
100106

101-
> Note to the workshop instructor: create a new user in the target AWS account called `lambda-workshop-user`.
102-
> Ensure it has full permissions to perform the required actions via Terraform. Create an access token for the `lambda-workshop-user`
103-
> user and share the Access Key ID and Secret Access Key with the workshop participants. Delete the user
104-
> when the workshop is complete.
107+
#### Create an IAM Role (Workshop Instructor Only)
108+
109+
> Note to the workshop instructor: This step only needs to be completed once, as the IAM role created
110+
> in this step will be shared by all workshop participants:
111+
112+
``` bash
113+
cd ~/workshop/lambda/iam_role
114+
terraform init
115+
terraform plan
116+
terraform apply
117+
```
118+
119+
> Note to the workshop instructor: After the workshop is complete, cleanup the role as follows:
120+
121+
``` bash
122+
cd ~/workshop/lambda/iam_role
123+
terraform destroy
124+
```
105125

106126
#### Terraform
107127
Terraform supports the passing of variables to ensure sensitive or dynamic data is not hard-coded in your .tf configuration files, as well as to make those values reusable throughout your resource definitions.

workshop/lambda/auto/main.tf

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,10 @@ provider "aws" {
1010

1111

1212
# Get IAM Role
13-
data "aws_caller_identity" "current" {}
14-
resource "aws_iam_role" "lambda_kinesis" {
13+
data "aws_iam_role" "lambda_kinesis" {
1514
name = "lambda_kinesis"
16-
assume_role_policy = jsonencode({
17-
Version = "2012-10-17"
18-
Statement = [
19-
{
20-
Action = "sts:AssumeRole"
21-
Effect = "Allow"
22-
Principal = {
23-
Service = "lambda.amazonaws.com"
24-
}
25-
}
26-
]
27-
})
28-
}
29-
resource "aws_iam_role_policy_attachment" "lambda_kinesis_execution" {
30-
role = aws_iam_role.lambda_kinesis.name
31-
policy_arn = "arn:aws:iam::aws:policy/AmazonKinesisFullAccess"
3215
}
3316

34-
resource "aws_iam_policy" "lambda_cloudwatch_logs" {
35-
name = "LambdaCloudWatchLogsCustomPolicy"
36-
policy = jsonencode({
37-
"Version": "2012-10-17",
38-
"Statement": [
39-
{
40-
"Effect": "Allow",
41-
"Action": [
42-
"logs:CreateLogStream",
43-
"logs:PutLogEvents"
44-
],
45-
"Resource": "*"
46-
}
47-
]
48-
})
49-
}
50-
51-
resource "aws_iam_role_policy_attachment" "lambda_cloudwatch_logs_attachment" {
52-
role = aws_iam_role.lambda_kinesis.name
53-
policy_arn = aws_iam_policy.lambda_cloudwatch_logs.arn
54-
}
5517

5618
# Create S3 Bucket, Ownership, ACL
5719
resource "aws_s3_bucket" "lambda_bucket" {
@@ -119,7 +81,7 @@ resource "aws_lambda_function" "lambda_producer" {
11981

12082
source_code_hash = data.archive_file.producer_app.output_base64sha256
12183

122-
role = aws_iam_role.lambda_kinesis.arn
84+
role = data.aws_iam_role.lambda_kinesis.arn
12385

12486
environment {
12587
variables = {
@@ -148,7 +110,7 @@ resource "aws_lambda_function" "lambda_consumer" {
148110

149111
source_code_hash = data.archive_file.consumer_app.output_base64sha256
150112

151-
role = aws_iam_role.lambda_kinesis.arn
113+
role = data.aws_iam_role.lambda_kinesis.arn
152114

153115
environment {
154116
variables = {

workshop/lambda/iam_role/main.tf

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
4+
default_tags {
5+
tags = {
6+
o11y-workshop = "lambda-tracing"
7+
}
8+
}
9+
}
10+
11+
12+
# Create IAM Role
13+
data "aws_caller_identity" "current" {}
14+
resource "aws_iam_role" "lambda_kinesis" {
15+
name = "lambda_kinesis"
16+
assume_role_policy = jsonencode({
17+
Version = "2012-10-17"
18+
Statement = [
19+
{
20+
Action = "sts:AssumeRole"
21+
Effect = "Allow"
22+
Principal = {
23+
Service = "lambda.amazonaws.com"
24+
}
25+
}
26+
]
27+
})
28+
}
29+
resource "aws_iam_role_policy_attachment" "lambda_kinesis_execution" {
30+
role = aws_iam_role.lambda_kinesis.name
31+
policy_arn = "arn:aws:iam::aws:policy/AmazonKinesisFullAccess"
32+
}
33+
34+
resource "aws_iam_policy" "lambda_cloudwatch_logs" {
35+
name = "LambdaCloudWatchLogsCustomPolicy"
36+
policy = jsonencode({
37+
"Version": "2012-10-17",
38+
"Statement": [
39+
{
40+
"Effect": "Allow",
41+
"Action": [
42+
"logs:CreateLogStream",
43+
"logs:PutLogEvents"
44+
],
45+
"Resource": "*"
46+
}
47+
]
48+
})
49+
}
50+
51+
resource "aws_iam_role_policy_attachment" "lambda_cloudwatch_logs_attachment" {
52+
role = aws_iam_role.lambda_kinesis.name
53+
policy_arn = aws_iam_policy.lambda_cloudwatch_logs.arn
54+
}

workshop/lambda/iam_role/outputs.tf

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5.38.0"
6+
}
7+
archive = {
8+
source = "hashicorp/archive"
9+
version = "~> 2.4.2"
10+
}
11+
}
12+
13+
required_version = "~> 1.2"
14+
}
15+

workshop/lambda/iam_role/variables.tf

Whitespace-only changes.

workshop/lambda/manual/main.tf

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,10 @@ provider "aws" {
1010

1111

1212
# Get IAM Role
13-
data "aws_caller_identity" "current" {}
14-
resource "aws_iam_role" "lambda_kinesis" {
13+
data "aws_iam_role" "lambda_kinesis" {
1514
name = "lambda_kinesis"
16-
assume_role_policy = jsonencode({
17-
Version = "2012-10-17"
18-
Statement = [
19-
{
20-
Action = "sts:AssumeRole"
21-
Effect = "Allow"
22-
Principal = {
23-
Service = "lambda.amazonaws.com"
24-
}
25-
}
26-
]
27-
})
28-
}
29-
resource "aws_iam_role_policy_attachment" "lambda_kinesis_execution" {
30-
role = aws_iam_role.lambda_kinesis.name
31-
policy_arn = "arn:aws:iam::aws:policy/AmazonKinesisFullAccess"
3215
}
3316

34-
resource "aws_iam_policy" "lambda_cloudwatch_logs" {
35-
name = "LambdaCloudWatchLogsCustomPolicy"
36-
policy = jsonencode({
37-
"Version": "2012-10-17",
38-
"Statement": [
39-
{
40-
"Effect": "Allow",
41-
"Action": [
42-
"logs:CreateLogStream",
43-
"logs:PutLogEvents"
44-
],
45-
"Resource": "*"
46-
}
47-
]
48-
})
49-
}
50-
51-
resource "aws_iam_role_policy_attachment" "lambda_cloudwatch_logs_attachment" {
52-
role = aws_iam_role.lambda_kinesis.name
53-
policy_arn = aws_iam_policy.lambda_cloudwatch_logs.arn
54-
}
5517

5618
# Create S3 Bucket, Ownership, ACL
5719
resource "aws_s3_bucket" "lambda_bucket" {
@@ -119,7 +81,7 @@ resource "aws_lambda_function" "lambda_producer" {
11981

12082
source_code_hash = data.archive_file.producer_app.output_base64sha256
12183

122-
role = aws_iam_role.lambda_kinesis.arn
84+
role = data.aws_iam_role.lambda_kinesis.arn
12385

12486
environment {
12587
variables = {
@@ -148,7 +110,7 @@ resource "aws_lambda_function" "lambda_consumer" {
148110

149111
source_code_hash = data.archive_file.consumer_app.output_base64sha256
150112

151-
role = aws_iam_role.lambda_kinesis.arn
113+
role = data.aws_iam_role.lambda_kinesis.arn
152114

153115
environment {
154116
variables = {

0 commit comments

Comments
 (0)