Asssumptions:
- AWS cli is installed
- Terraform is installed
- Python3 is installed
Pre-requisites:
- run aws configure and create the aws profile
- S3 bucket is created to store the lambda deployment package
terraform { | |
backend "s3" { | |
bucket = "com.demo.terraform.state" | |
encrypt = true | |
key = "terraform.tfstate" | |
region = "eu-west-2" | |
} | |
} |
stage { | |
name = "Source" | |
action { | |
name = "Source" | |
category = "Source" | |
owner = "AWS" | |
provider = "CodeStarSourceConnection" | |
version = "1" | |
output_artifacts = ["tf-code"] |
version: 0.2 | |
phases: | |
pre_build: | |
commands: | |
- terraform init | |
- terraform validate | |
build: | |
commands: | |
- terraform apply -auto-approve |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"secretsmanager:*" | |
], | |
"Resource": "*" | |
}, | |
{ |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"codestar-connections:*" | |
], | |
"Resource": "*" | |
}, | |
{ | |
"Effect": "Allow", |
Asssumptions:
Pre-requisites:
resource "aws_lambda_permission" "api-gateway-invoke-lambda" { | |
statement_id = "AllowAPIGatewayInvoke" | |
action = "lambda:InvokeFunction" | |
function_name = aws_lambda_function.sayhello.function_name | |
principal = "apigateway.amazonaws.com" | |
# The /*/* portion grants access from any method on any resource | |
# within the specified API Gateway. | |
source_arn = "${aws_api_gateway_rest_api.sayhello-api-gateway.execution_arn}/*/*" | |
} |
resource "aws_api_gateway_rest_api" "sayhello-api-gateway" { | |
name = "SayHelloAPI" | |
description = "Demo API to Say Hello" | |
api_key_source = "HEADER" | |
body = "${data.template_file.helloworld.rendered}" | |
endpoint_configuration { | |
types = ["REGIONAL"] | |
} | |
} |
# Lambda function returns a greeting | |
import urllib | |
import os | |
import sys | |
import json | |
def lambda_handler(event, context): |
Property | Description | |
---|---|---|
type | The integration type. In the case of lambda function integration use aws_proxy | |
uri | The ARN of the lambda function that implements the operation | |
httpMethod | Must always be POST | |
passthroughBehavior | Set to when_no_match as we do not have any conversion templates |