Chapter 14: 

  1. Write a Terraform template to create the InsertMovie Lambda function resources.

Answer: Setup execution role for the Lambda function:

resource "aws_iam_role" "role" {  name = "InsertMovieRole"  assume_role_policy = "${file("assume-role-policy.json")}"}resource "aws_iam_policy" "cloudwatch_policy" {  name = "PushCloudWatchLogsPolicy"  policy = "${file("cloudwatch-policy.json")}"}resource "aws_iam_policy" "dynamodb_policy" {  name = "ScanDynamoDBPolicy"  policy = "${file("dynamodb-policy.json")}"}resource "aws_iam_policy_attachment" "cloudwatch-attachment" {  name = "cloudwatch-lambda-attchment"  roles = ["${aws_iam_role.role.name}"]  policy_arn = "${aws_iam_policy.cloudwatch_policy.arn}"}resource "aws_iam_policy_attachment" "dynamodb-attachment" ...

Get Hands-On Serverless Applications with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.