GithubHelp home page GithubHelp logo

syyunn / git-lambda-layer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lambci/git-lambda-layer

0.0 1.0 0.0 120.26 MB

A layer for AWS Lambda that allows your functions to use `git` and `ssh` binaries

License: MIT License

Shell 75.57% JavaScript 24.43%

git-lambda-layer's Introduction

Git (w/ ssh) binaries for AWS Lambda

A layer for AWS Lambda that allows your functions to use git and ssh binaries.

Getting Started

You can add this layer to any Lambda function you want. PATH already includes /opt/bin in Lambda, which is where it will be mounted.

Click on Layers and choose "Add a layer", and "Provide a layer version ARN" and enter the following ARN (replace us-east-1 with the region of your Lambda):

arn:aws:lambda:us-east-1:553035198032:layer:git:8

Note: If you're using the nodejs10.x runtime, then you'll need to use a slightly different layer:

arn:aws:lambda:us-east-1:553035198032:layer:git-lambda2:2

(again, replacing us-east-1 with the region of your Lambda)

Provide layer ARN

Then click Add, save your lambda and test it out!

Referenced layers

Simple example on Node.js w/ https

const { execSync } = require('child_process')

exports.handler = async(event) => {
  execSync('rm -rf /tmp/*', { encoding: 'utf8', stdio: 'inherit' })

  execSync('cd /tmp && git clone https://github.com/mhart/aws4', { encoding: 'utf8', stdio: 'inherit' })

  return execSync('ls /tmp/aws4', { encoding: 'utf8' }).split('\n')
}

Complex example on Node.js w/ ssh

const fs = require('fs')
const { execSync } = require('child_process')

exports.handler = async(event) => {
  execSync('rm -rf /tmp/*', { encoding: 'utf8', stdio: 'inherit' })

  fs.writeFileSync('/tmp/known_hosts', 'github.com,192.30.252.*,192.30.253.*,192.30.254.*,192.30.255.* ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==')

  // Get this from a safe place, say SSM
  fs.writeFileSync('/tmp/id_rsa', `-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
`)
  execSync('chmod 400 /tmp/id_rsa', { encoding: 'utf8', stdio: 'inherit' })

  process.env.GIT_SSH_COMMAND = 'ssh -o UserKnownHostsFile=/tmp/known_hosts -i /tmp/id_rsa'

  execSync('git clone --depth 1 ssh://[email protected]/mhart/aws4.git /tmp/aws4', { encoding: 'utf8', stdio: 'inherit' })

  return execSync('ls /tmp/aws4', { encoding: 'utf8' }).split('\n')
}

ssh always tries to create a .ssh directory – this is something you can't avoid, nor can you specify your own destination for this – which means you'll see a warning similar to the following:

Could not create directory '/home/sbx_user1075/.ssh'.

You can ignore this warning – ssh should continue to execute past this point, assuming you have the UserKnownHostsFile option correct and it contains the signature of the host you're trying to connect to. Alternatively, you can use -o StrictHostKeyChecking=no if you're not concerned about MiTM attacks.

Version ARNs for Amazon Linux 2 runtimes (nodejs10.x)

Git version openssh version ARN
2.24.0 OpenSSH_7.4p1, OpenSSL 1.0.2k-fips arn:aws:lambda:<region>:553035198032:layer:git-lambda2:2
2.23.0 OpenSSH_7.4p1, OpenSSL 1.0.2k-fips arn:aws:lambda:<region>:553035198032:layer:git-lambda2:1

Version ARNs for all other runtimes

Git version openssh version ARN
2.24.0 OpenSSH_7.4p1, OpenSSL 1.0.2k-fips arn:aws:lambda:<region>:553035198032:layer:git:8
2.23.0 OpenSSH_7.4p1, OpenSSL 1.0.2k-fips arn:aws:lambda:<region>:553035198032:layer:git:7
2.21.0 OpenSSH_7.4p1, OpenSSL 1.0.2k-fips arn:aws:lambda:<region>:553035198032:layer:git:6
2.20.0 OpenSSH_6.6.1p1, OpenSSL 1.0.1k-fips arn:aws:lambda:<region>:553035198032:layer:git:3
2.19.2 OpenSSH_6.6.1p1, OpenSSL 1.0.1k-fips arn:aws:lambda:<region>:553035198032:layer:git:2

git-lambda-layer's People

Contributors

mhart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.