├── .editorconfig ├── .gitattributes ├── .github └── workflows │ ├── layers_dispatch.yaml │ └── update_readme.yaml ├── .gitignore ├── .tag_version ├── license ├── readme.md └── renovate.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | charset = utf-8 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | *.zip filter=lfs diff=lfs merge=lfs -text 4 | chrome_aws_lambda.zip filter=lfs diff=lfs merge=lfs -text 5 | chromium.zip filter=lfs diff=lfs merge=lfs -text 6 | -------------------------------------------------------------------------------- /.github/workflows/layers_dispatch.yaml: -------------------------------------------------------------------------------- 1 | name: Deploy Layers 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | schedule: 8 | - cron: '0 0 * * *' # This will run the workflow daily at midnight 9 | 10 | env: 11 | AWS_REGIONS: "us-east-1 us-east-2 us-west-1 us-west-2 ca-central-1 eu-central-1 eu-west-1 eu-west-2 eu-west-3 eu-north-1 ap-northeast-1 ap-northeast-2 ap-southeast-1 ap-southeast-2 ap-south-1 sa-east-1" 12 | S3_BUCKET_NAME: "shelf-lambda-layers" 13 | 14 | jobs: 15 | check_release: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@v2 21 | 22 | - name: Setup AWS CLI 23 | uses: aws-actions/configure-aws-credentials@v1 24 | with: 25 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 26 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 27 | aws-region: us-east-1 28 | 29 | - name: Get Previous Tag Version 30 | id: prev_tag_version 31 | run: echo "::set-output name=tag::$(cat .tag_version || echo '')" 32 | 33 | - name: Get Latest Release URL and Tag Version 34 | id: latest_release 35 | run: | 36 | JSON_RESPONSE=$(curl -s https://api.github.com/repos/Sparticuz/chromium/releases/latest) 37 | LATEST_RELEASE_URL=$(echo $JSON_RESPONSE | grep -Po '"browser_download_url": "\K[^"]+' | awk 'NR==1') 38 | TAG_VERSION=$(echo $JSON_RESPONSE | grep -Po '"tag_name": "\K[^"]+') 39 | if [[ "$TAG_VERSION" == "${{ steps.prev_tag_version.outputs.tag }}" ]]; then 40 | echo "Skipping as the tag version is the same as the previous run." 41 | exit 78 42 | fi 43 | echo "LATEST_RELEASE_URL=$LATEST_RELEASE_URL" >> $GITHUB_ENV 44 | echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV 45 | echo "FILENAME=chromium-$TAG_VERSION.zip" >> $GITHUB_ENV 46 | 47 | - name: Update Tag Version 48 | run: echo ${{ env.TAG_VERSION }} > .tag_version 49 | 50 | - name: Download Latest Release 51 | run: | 52 | curl -LO ${{ env.LATEST_RELEASE_URL }} 53 | FILEPATH=$(basename ${{ env.LATEST_RELEASE_URL }}) 54 | echo "FILEPATH=$FILEPATH" >> $GITHUB_ENV 55 | 56 | - name: Upload to S3 57 | run: | 58 | for REGION in ${{ env.AWS_REGIONS }}; do 59 | BUCKET_NAME="${{ env.S3_BUCKET_NAME }}-$REGION" 60 | aws configure set region $REGION 61 | aws s3 cp ${{ env.FILEPATH }} s3://$BUCKET_NAME/${{ env.FILENAME }} & 62 | done 63 | wait 64 | 65 | - name: Publish to AWS Regions with Permissions 66 | run: | 67 | for REGION in ${{ env.AWS_REGIONS }}; do 68 | BUCKET_NAME="${{ env.S3_BUCKET_NAME }}-$REGION" 69 | 70 | aws configure set region $REGION 71 | 72 | { 73 | NEW_VERSION_NUMBER=$(aws lambda publish-layer-version \ 74 | --layer-name chrome-aws-lambda \ 75 | --content S3Bucket=$BUCKET_NAME,S3Key=${{ env.FILENAME }} \ 76 | --region $REGION \ 77 | --compatible-architecture x86_64 \ 78 | --description "@sparticuz/chromium v${{ env.TAG_VERSION }} & Chromium v${{ env.TAG_VERSION }}" \ 79 | --query Version \ 80 | --output text) 81 | 82 | aws lambda add-layer-version-permission \ 83 | --region "$REGION" \ 84 | --layer-name chrome-aws-lambda \ 85 | --statement-id sid1 \ 86 | --action lambda:GetLayerVersion \ 87 | --principal '*' \ 88 | --version-number $NEW_VERSION_NUMBER 89 | echo "Published and permissions added for ${{ env.FILENAME }} in $REGION" 90 | } & 91 | done 92 | wait 93 | 94 | 95 | - name: Commit Tag Version 96 | run: | 97 | git config --local user.email "action@github.com" 98 | git config --local user.name "GitHub Action" 99 | git add .tag_version 100 | git commit -m "Update tag version to ${{ env.TAG_VERSION }}" 101 | git push 102 | -------------------------------------------------------------------------------- /.github/workflows/update_readme.yaml: -------------------------------------------------------------------------------- 1 | name: Update README 2 | 3 | on: 4 | # push: 5 | # branches: 6 | # - master 7 | workflow_run: 8 | workflows: ["Deploy Layers"] 9 | types: 10 | - completed 11 | 12 | jobs: 13 | update_readme: 14 | runs-on: ubuntu-latest 15 | if: ${{ github.event.workflow_run.conclusion == 'success' }} 16 | env: 17 | AWS_REGIONS: "us-east-1 us-east-2 us-west-1 us-west-2 ca-central-1 eu-central-1 eu-west-1 eu-west-2 eu-west-3 eu-north-1 ap-northeast-1 ap-northeast-2 ap-southeast-1 ap-southeast-2 ap-south-1 sa-east-1" 18 | 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v2 22 | 23 | - name: Setup AWS CLI 24 | uses: aws-actions/configure-aws-credentials@v1 25 | with: 26 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 27 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 28 | aws-region: us-east-1 29 | 30 | - name: Get Latest Release URL and Tag Version 31 | run: | 32 | JSON_RESPONSE=$(curl -s https://api.github.com/repos/Sparticuz/chromium/releases/latest) 33 | TAG_VERSION=$(echo $JSON_RESPONSE | grep -Po '"tag_name": "\K[^"]+') 34 | echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV 35 | 36 | - name: Update README 37 | run: | 38 | TAG_VERSION=${{ env.TAG_VERSION }} 39 | ARN_BASE="arn:aws:lambda:" 40 | ARN_SUFFIX=":764866452798:layer:chrome-aws-lambda:" 41 | 42 | sed -i -e "s|Has Chromium v[0-9\.]*|Has Chromium $TAG_VERSION|g" readme.md 43 | 44 | for REGION in ${{ env.AWS_REGIONS }}; do 45 | LAYER_VERSION=$(aws lambda list-layer-versions --layer-name chrome-aws-lambda --region $REGION --query 'LayerVersions[0].LayerVersionArn' --output text | grep -oE '[0-9]+$') 46 | ARN="$ARN_BASE$REGION$ARN_SUFFIX$LAYER_VERSION" 47 | sed -i -e "s|arn:aws:lambda:$REGION:[0-9]*:layer:chrome-aws-lambda:[0-9]*|$ARN|g" readme.md 48 | done 49 | 50 | - name: Commit and Push 51 | run: | 52 | git config --local user.email "action@github.com" 53 | git config --local user.name "GitHub Action" 54 | git add readme.md 55 | git commit -m "Update README with new version details [ci skip]" 56 | git push 57 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | coverage/ 3 | node_modules/ 4 | temp 5 | yarn.lock 6 | *.log 7 | .DS_Store 8 | lib/ 9 | layer/ 10 | -------------------------------------------------------------------------------- /.tag_version: -------------------------------------------------------------------------------- 1 | v133.0.0 2 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Gemshelf Inc. (shelf.io) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Google Chrome for AWS Lambda as a layer 2 | 3 | > 58 MB Google Chrome to fit inside AWS Lambda Layer compressed with Brotli 4 | 5 | [Sparticuz/chromium](https://github.com/Sparticuz/chromium) published as a Lambda Layer. 6 | 7 | Tested with Node.js 16x/18x. Compatible with x86_64 only. Has Chromium v131.0.0 8 | 9 | ## Getting Started 10 | 11 | Click on Layers and choose "Add a layer", and "Provide a layer version 12 | ARN" and enter the following ARN. 13 | 14 | ``` 15 | arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:50 16 | ``` 17 | 18 | When importing the module within lambda, make sure you import `@sparticuz/chromium` not `chrome-aws-lambda` 19 | 20 | ```js 21 | const chromium = require('@sparticuz/chromium'); 22 | ``` 23 | 24 | **package.json** 25 | 26 | - `@sparticuz/chromium` marked as a dependency 27 | - `puppeteer-core` marked as a dependency 28 | 29 | **lambda container settings**: 30 | 31 | - x86_64 architecture 32 | - > =1024mb memory 33 | - `@sparticuz/chromium` marked as an externalModule in the bundling settings 34 | - A lambda layer marked like so (this is CDK code, but convert to SAM or whatever at will): 35 | 36 | ```ts 37 | layers: [LayerVersion.fromLayerVersionArn(this, 'chromium-lambda-layer', 38 | 'arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:50' 39 | )] 40 | ``` 41 | 42 | **In the deployed lambda code** 43 | You can just use a regular ES6 or CommonJS import statement for `@sparticuz/chrome-aws-lambda`, and just use as 44 | indicated. 45 | 46 | ## Available regions 47 | 48 | * ap-northeast-1: `arn:aws:lambda:ap-northeast-1:764866452798:layer:chrome-aws-lambda:50` 49 | * ap-northeast-2: `arn:aws:lambda:ap-northeast-2:764866452798:layer:chrome-aws-lambda:49` 50 | * ap-south-1: `arn:aws:lambda:ap-south-1:764866452798:layer:chrome-aws-lambda:50` 51 | * ap-southeast-1: `arn:aws:lambda:ap-southeast-1:764866452798:layer:chrome-aws-lambda:50` 52 | * ap-southeast-2: `arn:aws:lambda:ap-southeast-2:764866452798:layer:chrome-aws-lambda:50` 53 | * ca-central-1: `arn:aws:lambda:ca-central-1:764866452798:layer:chrome-aws-lambda:50` 54 | * eu-north-1: `arn:aws:lambda:eu-north-1:764866452798:layer:chrome-aws-lambda:50` 55 | * eu-central-1: `arn:aws:lambda:eu-central-1:764866452798:layer:chrome-aws-lambda:50` 56 | * eu-west-1: `arn:aws:lambda:eu-west-1:764866452798:layer:chrome-aws-lambda:50` 57 | * eu-west-2: `arn:aws:lambda:eu-west-2:764866452798:layer:chrome-aws-lambda:50` 58 | * eu-west-3: `arn:aws:lambda:eu-west-3:764866452798:layer:chrome-aws-lambda:50` 59 | * sa-east-1: `arn:aws:lambda:sa-east-1:764866452798:layer:chrome-aws-lambda:50` 60 | * us-east-1: `arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:50` 61 | * us-east-2: `arn:aws:lambda:us-east-2:764866452798:layer:chrome-aws-lambda:50` 62 | * us-west-1: `arn:aws:lambda:us-west-1:764866452798:layer:chrome-aws-lambda:50` 63 | * us-west-2: `arn:aws:lambda:us-west-2:764866452798:layer:chrome-aws-lambda:50` 64 | 65 | ## License 66 | 67 | MIT © [Shelf](https://shelf.io) 68 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["github>shelfio/renovate-config-public"], 3 | "labels": ["backend"] 4 | } 5 | --------------------------------------------------------------------------------