Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions apm-lambda-extension/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
build:
GOOS=linux GOARCH=amd64 go build -o bin/extensions/apm-lambda-extension main.go

build-GoExampleExtensionLayer:
GOOS=linux GOARCH=amd64 go build -o $(ARTIFACTS_DIR)/extensions/apm-lambda-extension main.go
chmod +x $(ARTIFACTS_DIR)/extensions/apm-lambda-extension

ifndef GOARCH
GOARCH=amd64
endif
GOOS=linux go build -o bin/extensions/apm-lambda-extension main.go
chmod +x bin/extensions/apm-lambda-extension
build-and-publish:
ifndef AWS_DEFAULT_REGION
$(error AWS_DEFAULT_REGION is undefined)
Expand All @@ -18,11 +17,15 @@ endif
ifndef ELASTIC_LAYER_NAME
$(error ELASTIC_LAYER_NAME is undefined)
endif
make build
cd bin && rm -f extension.zip || true && zip -r extension.zip extensions
GOARCH=${GOARCH} make build
GOARCH=${GOARCH} make zip
aws lambda publish-layer-version --layer-name "${ELASTIC_LAYER_NAME}" --zip-file "fileb://./bin/extension.zip"
run-GoExampleExtensionLayer:
go run apm-lambda-extension/main.go

zip:
cd bin && rm -f extension.zip || true && zip -r extension.zip extensions && cp extension.zip ${GOARCH}.zip
test:
go test extension/*.go -v
env:
ifndef GOARCH
export GOARCH=amd64
endif
env
1 change: 1 addition & 0 deletions apm-lambda-extension/cli/build-and-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function getLastJsonFromShellOutput(output) {
jsonLines.push(line)
}
}

const string = jsonLines.join('')
const object = JSON.parse(string)
return object
Expand Down
21 changes: 20 additions & 1 deletion apm-lambda-extension/cli/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

const AWS = require('aws-sdk')
AWS.config.update({region: process.env.AWS_DEFAULT_REGION});
const fs = require('fs')
const yaml = require('js-yaml')
const { exec, /*execFile*/ } = require("child_process")
Expand Down Expand Up @@ -58,16 +60,33 @@ async function cmd(argv) {
config.lambda_env.ELASTIC_APM_LAMBDA_APM_SERVER = config.lambda_env.ELASTIC_APM_SERVER_URL
config.lambda_env.ELASTIC_APM_SERVER_URL = 'http://localhost:8200'

const lambda = new AWS.Lambda({apiVersion:'2015-03-31'})
const configuration = await lambda.getFunction({
FunctionName: config.function_name
}).promise();
console.log(configuration.Configuration.Architectures.length)
if( !Array.isArray(configuration.Configuration.Architectures) ||
configuration.Configuration.Architectures.length !== 1) {
console.log("Unexpected configuration.Configuration.Architectures type from function, exiting.")
process.exit(1)
}

const arch = configuration.Configuration.Architectures.pop()
if(arch !== 'arm64' && arch != 'amd64') {
console.log("Unexpected configuration.Configuration.Architectures value, exiting.")
process.exit(1)
}

// run command to set env variables
try {
process.env['GOARCH'] = arch
const output = await runShellCommand(
__dirname + '/elastic-lambda.js',
['update-function-env',config.function_name, JSON.stringify(config.lambda_env)],
'updating lambda function\'s env variables'
)
console.log(output)
} catch(error) {
console.log(error)
console.log('encountered error, exiting')
process.exit(1)
}
Expand Down