<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Aws-Lambda on despatches</title><link>https://icle.es/tags/aws-lambda/</link><description>Recent content in Aws-Lambda on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 19 Jun 2025 21:38:42 +0100</lastBuildDate><atom:link href="https://icle.es/tags/aws-lambda/index.xml" rel="self" type="application/rss+xml"/><item><title>How to get current Function URL (aws-lambda + golang)</title><link>https://icle.es/2023/11/08/how-to-get-current-function-url-aws-lambda-golang/</link><pubDate>Wed, 08 Nov 2023 12:10:16 +0000</pubDate><guid>https://icle.es/2023/11/08/how-to-get-current-function-url-aws-lambda-golang/</guid><description>&lt;p>When deploying a function lambda that needs details of its own function URL.
It's an OAuth Callback, and needs to calculate the redirect. There are possible
security issues doing it this way, so will switch to http gateway on launch. In
the meantime, though, I ran into a bit of a chicken and egg problem.&lt;/p>
&lt;p>In Pulumi, the function URL is created after the function (and even otherwise),
I can't pass the output of the lambda (or lambdaFunctionUrl) back in as an
environment variable. Fortunately, there is an easy way to pick up the Function
URL (or the function name for that matter) - if you know how ;)&lt;/p></description><content:encoded><![CDATA[<p>When deploying a function lambda that needs details of its own function URL.
It's an OAuth Callback, and needs to calculate the redirect. There are possible
security issues doing it this way, so will switch to http gateway on launch. In
the meantime, though, I ran into a bit of a chicken and egg problem.</p>
<p>In Pulumi, the function URL is created after the function (and even otherwise),
I can't pass the output of the lambda (or lambdaFunctionUrl) back in as an
environment variable. Fortunately, there is an easy way to pick up the Function
URL (or the function name for that matter) - if you know how ;)</p>
```wp-block-syntaxhighlighter-code
   domainName := request.RequestContext.DomainName
    funcName := os.Getenv("AWS_LAMBDA_FUNCTION_NAME")
    return fmt.Sprintf("Domain: %s, funcName: %s", domainName, funcName), nil
```
<p>There are other
<a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime">defined lambda function environment variables</a>
as well that you can use.</p>
]]></content:encoded></item><item><title>Including a built artifact in another target (Bazel, golang)</title><link>https://icle.es/2023/11/01/including-a-built-artifact-in-another-target-bazel-golang/</link><pubDate>Wed, 01 Nov 2023 19:42:30 +0000</pubDate><guid>https://icle.es/2023/11/01/including-a-built-artifact-in-another-target-bazel-golang/</guid><description>&lt;p>We use pulumi to do IaC and we use a monorepo with Bazel as the build tool. We
have out modules set out as following&lt;/p>
&lt;p>One of the requirements we have is to build a lambda module and then deploy it.
The lambda module is a target being built by Bazel (golang, but shouldn't
matter):&lt;/p>
```go
go_binary(
 name = "lambda_module",
 visibility = ["//visibility:public"],
)
```</description><content:encoded><![CDATA[<p>We use pulumi to do IaC and we use a monorepo with Bazel as the build tool. We
have out modules set out as following</p>
<p>One of the requirements we have is to build a lambda module and then deploy it.
The lambda module is a target being built by Bazel (golang, but shouldn't
matter):</p>
```go
go_binary(
    name = "lambda_module",
    visibility = ["//visibility:public"],
)
```
<p>We then have the iac module, which should get the built version of the above
module, so that it can then upload it into lambda</p>
```go
go_binary(
    name = "iac",
    args = [
        "-lambda_module",
        "$(location //products/productA/module/lambda_module)",
    ],
    data = ["//products/productA/module/lambda_module"],
    visibility = ["//visibility:public"],
)
```
<p>There are two key parameters here to note:</p>
<ul>
<li><code>args</code>: We generate the path to the target module using
<code> //products/productA/module/lambda_module)</code></li>
<li><code>data</code>: We use the data tag to ensure that the built output is included when
building/running this target</li>
</ul>
<p>We then need to use runfiles support within golang to be ablet to identify the
correct location for the built binary. The reason this part is complex is to be
able to support multiple operating systems. I should caveat that I have only got
this working on Linux, but Mac/Win shouldn't be too different.</p>
```go
package main

import (
    _ "embed"
    "flag"
    "fmt"
    "github.com/bazelbuild/rules_go/go/runfiles"
    "path/filepath"
)

func main() {

    var webhookAuth = flag.String("webhook_auth", "", "bin for webhook_auth")
    flag.Parse()
    fmt.Printf("param : %s \n", *webhookAuth)

    path, err := runfiles.Rlocation(fmt.Sprintf("workspace_name/%s", *webhookAuth))
    fmt.Printf("rLoc path: %s, err: %v \n", path, err)

    symlinks, err := filepath.EvalSymlinks(path)
    fmt.Printf("evaluated path: %s, err: %v \n", symlinks, err)

}
```
<p>We use the flag module to retrieve the path passed in as a runtime parameter</p>
<p>We use <code>runfiles.Rlocation</code> to pick up the &quot;real&quot; path to the file, prepending
the workspace name to the start. You can
<a href="https://bazel.build/rules/lib/globals/workspace#workspace">define the workspace name</a>
in the root WORKSPACE file with <code>workspace(name = &quot;workspace_name&quot;)</code></p>
<p>Finally, resolve the Symlink to get the actual file path</p>
<h2 id="references">References</h2>
<p>There are similar mechanisms to find the rLocation in other languages, a couple
of which are described in
<a href="https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub">its design document</a></p>
<p>There is some documentation in <code>rules_go</code> around
<a href="https://github.com/bazelbuild/rules_go#how-do-i-access-go_binary-executables-from-go_test">accessing <code>go_binary</code> from <code>go_test</code></a>
which I referenced and updated to get the above example</p>
<p>I found the above link from
<a href="https://stackoverflow.com/questions/70193581/feed-bazel-output-to-another-bazel-rule">a stackoverflow post about feeding bazel output to another bazel rule</a></p>]]></content:encoded></item></channel></rss>