Skip to content

Commit ef83769

Browse files
committed
updated to use account id from data source and region from variables file
1 parent de575df commit ef83769

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
FROM amazonlinux:latest
1+
FROM amazonlinux:2.0.20230727.0
22

33
RUN yum install -y tar xz gzip gcc
44

5-
RUN curl -L -o golang.tar.gz https://go.dev/dl/go1.20.7.linux-amd64.tar.gz
5+
RUN curl -L -o golang.tar.gz https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
66

7-
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf golang.tar.gz
7+
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf golang.tar.gz
88

99
WORKDIR /project
1010

1111
COPY go.mod go.sum ./
12-
1312
RUN /usr/local/go/bin/go mod download -x
1413

14+
RUN /usr/local/go/bin/go install github.com/mattn/go-sqlite3
1515
ENV PATH="${PATH}:/usr/local/go/bin"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This repository contains example lambda handler integration with API gateway. Te
1515
## Setup (optional)
1616

1717
### Docker
18+
1819
Although not require specifically to run go in lambdas, can be useful to avoid compatibility issues
1920
when using cgo bindings or third party libraries using cgo such as sqlite3.
2021

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/JayJamieson/go-lambda
22

3-
go 1.20
3+
go 1.21
44

55
require github.com/aws/aws-lambda-go v1.41.0

infrastructure/api-gateway.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ resource "aws_lambda_permission" "api_gateway_lambda" {
5454
action = "lambda:InvokeFunction"
5555
function_name = aws_lambda_function.go_lambda.function_name
5656
principal = "apigateway.amazonaws.com"
57-
source_arn = "arn:aws:execute-api:ap-southeast-2:834849242330:${aws_api_gateway_rest_api.lambda_api.id}/*"
57+
source_arn = "arn:aws:execute-api:${var.region}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.lambda_api.id}/*"
5858
}
5959

6060
resource "aws_api_gateway_usage_plan" "lambda_api_usage" {

infrastructure/main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ provider "aws" {
1111
region = var.region
1212
}
1313

14+
data "aws_caller_identity" "current" {}
15+
1416
data "archive_file" "lambda" {
1517
type = "zip"
1618
source_file = "bootstrap"
@@ -59,7 +61,7 @@ resource "aws_iam_policy" "lambda_execution_policy" {
5961
Action = ["logs:CreateLogGroup"]
6062
Effect = "Allow"
6163
Resource = [
62-
"arn:aws:logs:ap-southeast-2:834849242330:*"
64+
"arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:*"
6365
]
6466
},
6567
{
@@ -68,7 +70,7 @@ resource "aws_iam_policy" "lambda_execution_policy" {
6870
"logs:CreateLogStream",
6971
"logs:PutLogEvents"
7072
],
71-
Resource = "arn:aws:logs:ap-southeast-2:834849242330:log-group:*"
73+
Resource = "arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:log-group:*"
7274
}
7375
]
7476
})

0 commit comments

Comments
 (0)