-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example of deploying a Go project to fargate.
- Loading branch information
Showing
9 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
load("@rules_oci//oci:defs.bzl", "oci_image") | ||
load("@rules_pkg//pkg:tar.bzl", "pkg_tar") | ||
load("//bzl:rules.bzl", "bazel_lint") | ||
load("//go:rules.bzl", "go_binary", "go_library") | ||
load("//ts:rules.bzl", "ts_project") | ||
load("//ts/pulumi/lib/oci:rules.bzl", "pulumi_image") | ||
|
||
go_library( | ||
name = "hello_world_lib", | ||
srcs = ["hello.go"], | ||
importpath = "github.com/zemn-me/monorepo/ts/pulumi/zemn.me/hello_world", | ||
visibility = ["//visibility:private"], | ||
deps = ["@com_github_aws_aws_lambda_go//lambda"], | ||
) | ||
|
||
go_binary( | ||
name = "hello_world", | ||
embed = [":hello_world_lib"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
bazel_lint( | ||
name = "bazel_lint", | ||
srcs = ["BUILD.bazel"], | ||
) | ||
|
||
pkg_tar( | ||
name = "tar", | ||
srcs = [":hello_world"], | ||
) | ||
|
||
oci_image( | ||
name = "image", | ||
base = "@distroless_base", | ||
entrypoint = ["/hello_world"], | ||
tars = [":tar"], | ||
) | ||
|
||
pulumi_image( | ||
name = "oci_image", | ||
src = ":image", | ||
component_name = "HelloWorldImage", | ||
) | ||
|
||
ts_project( | ||
name = "ts", | ||
srcs = [ | ||
"hello_world.ts", | ||
], | ||
visibility = [ | ||
"//ts/pulumi:__subpackages__", | ||
], | ||
deps = [ | ||
":oci_image", | ||
"//:node_modules/@pulumi/aws", | ||
"//:node_modules/@pulumi/awsx", | ||
"//:node_modules/@pulumi/pulumi", | ||
"//ts/pulumi/lib", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-lambda-go/lambda" | ||
) | ||
|
||
// Handler is the Lambda function entry point | ||
func Handler(ctx context.Context) (string, error) { | ||
return "Hello, World!", nil | ||
} | ||
|
||
func main() { | ||
// Start the Lambda function | ||
lambda.Start(Handler) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as aws from "@pulumi/aws"; | ||
import { ComponentResource, ComponentResourceOptions } from "@pulumi/pulumi"; | ||
|
||
import { mergeTags, TagSet, tagTrue } from "#root/ts/pulumi/lib/tags.js"; | ||
import { HelloWorldImage } from "#root/ts/pulumi/zemn.me/hello_world/HelloWorldImage.js"; | ||
|
||
export interface Args { | ||
tags?: TagSet; | ||
} | ||
|
||
export class LambdaHelloWorld extends ComponentResource { | ||
constructor( | ||
name: string, | ||
args: Args, | ||
opts?: ComponentResourceOptions | ||
) { | ||
super("ts:pulumi:Component", name, args, opts); | ||
|
||
const tag = name; | ||
const tags = mergeTags(args.tags, tagTrue(tag)); | ||
|
||
// Create the ECR repository to store our container image | ||
const repo = new aws.ecr.Repository("repo", { | ||
forceDelete: true, | ||
tags: tags, | ||
}); | ||
|
||
// Build and push the container image | ||
const img = new HelloWorldImage(`${name}_img`, { | ||
repository: repo.repositoryUrl, | ||
}); | ||
|
||
// Create the Lambda function using the container image | ||
const lambda = new aws.lambda.Function("lambda", { | ||
packageType: "Image", | ||
imageUri: img.url, | ||
role: new aws.iam.Role("lambdaRole", { | ||
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ | ||
Service: "lambda.amazonaws.com", | ||
}), | ||
}).arn, | ||
timeout: 30, | ||
memorySize: 512, | ||
tags: tags, | ||
}); | ||
|
||
// Add permissions for Lambda to log to CloudWatch | ||
new aws.iam.RolePolicyAttachment("lambdaLogging", { | ||
role: lambda.role!, | ||
policyArn: aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole, | ||
}); | ||
|
||
// Export the Lambda function name | ||
this.registerOutputs({ | ||
lambdaFunctionName: lambda.name, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters