3

I wrote a bash script similar to this one: Download an already uploaded Lambda function

Everything is fine with all lambda functions that have been deployed via SAM template files. However, when I retrieve the deployment package of a lambda function (application) that has been deployed via the web UI of AWS, all I get is the index.js file in the deployment package of that function.

Anyway, it is possible to generate a SAM yaml file that describes the architecture of the given lambda application by selecting it over the Lambda Management Console via Actions > Export Function > Download AWS SAM file. Consequently, there should be a possibility to do this via aws-cli or is that not possible at all?

2 Answers 2

1

You can get function configuration with awscli https://docs.aws.amazon.com/cli/latest/reference/lambda/get-function-configuration.html and the response will contain a Code section with a link to the function package https://docs.aws.amazon.com/lambda/latest/dg/API_FunctionCodeLocation.html

Also, you can create a CloudFormation stack from the existing infrastructure with CloudFormer https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-cloudformer.html

Having a CloudFormation template you can get the resource description. https://docs.aws.amazon.com/cli/latest/reference/cloudformation/describe-stack-resources.html with the link to the function source code on S3.

See more on this in https://stackoverflow.com/a/55764927/6628583

Sign up to request clarification or add additional context in comments.

1 Comment

However, when I get the link to the function package, there is only the handler function since there was never a SAM template used when the function was deployed via UI. I need a way to get this infrastructure as code representation just like in the web-ui in order to retrieve a SAM template of the deployed function..
0

This is a clue, not a complete answer, sorry. There should be, but there is not yet, an aws-cli to get this SAM content. The URI in the browser is obtuse with some obscure network calls, e.g.

https://us-west-2.console.aws.amazon.com/p/log/1/lambda/1/OP/&k0=feevc&m0=1&d0=%7B%22s_fid%22:%2233SNIPPEDC66-34SNIPPED7FE5B%22%7D&p0=exportSAM&cb=1595621538378&proxy-rid=7c6a6a31SNIPPEDf1a400b457cc

There seems to be no easy way to construct that URI to GET the exportSAM download.

The browser lambda.js is not much help, e.g.

        var A = Object(p.connect)((function(e) {
            return {
                blueprint: Object(v.b)(e).query.exportBp,
                integrationConfigs: h.c.getNodes(e),
                downloadMessages: h.c.getDownloadMessages(e),
                isOpen: !!Object(v.b)(e).query.exportModal,
                exporting: h.c.getExporting(e)
            }
        }
        ), (function(e) {
            return {
                downloadSam: function(t) {
                    return e((n = t,
                    {
                        type: b.f.EXPORT_BLUEPRINT_TO_FLOURISH,
                        blueprintName: n
                    }));
                    var n
                },
                close: function() {
                    return e(Object(m.c)({
                        query: {
                            exportModal: void 0,
                            exportBp: void 0
                        }
                    }, {
                        persistQuery: !0
                    }))
                }
            }
        }
        ), (function(e, t, n) {
            return S(S(S(S({}, n), e), t), {}, {
                downloadSam: function() {
                    return t.downloadSam(e.blueprint)
                }
            })
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.