Skip to content

Instantly share code, notes, and snippets.

View cliffdias's full-sized avatar

cliff dias cliffdias

View GitHub Profile
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",
@cliffdias
cliffdias / README.md
Last active February 18, 2021 15:31
Execution steps

Asssumptions:

  1. AWS cli is installed
  2. Terraform is installed
  3. Python3 is installed

Pre-requisites:

  1. run aws configure and create the aws profile
  2. S3 bucket is created to store the lambda deployment package
@cliffdias
cliffdias / lambdapermissions.tf
Created February 18, 2021 12:18
Lambda permissions
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}/*/*"
}
@cliffdias
cliffdias / apigateway.tf
Created February 18, 2021 12:12
API Module
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"]
}
}
@cliffdias
cliffdias / sayhello.py
Created February 18, 2021 10:55
Lambda function implementing the API
# 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