If you are beginning your journey with Senzing, please start with Senzing Quick Start guides.
You are in the Senzing Garage where projects are "tinkered" on. Although this GitHub repository may help you understand an approach to using Senzing, it's not considered to be "production ready" and is not considered to be part of the Senzing product. Heck, it may not even be appropriate for your application of Senzing!
An AWS Lambda Python program for generating self-signed certificates.
The instructions show how to generate a package that is loaded onto AWS S3 and used by https://github.com/senzing-garage/aws-cloudformation-ecs-poc-simple AWS Cloudformation.
- Preamble
- Related artifacts
- Demonstrate using Command Line Interface
- Demonstrate using Docker
- Develop
- Advanced
- Errors
- References
At Senzing, we strive to create GitHub documentation in a "don't make me think" style. For the most part, instructions are copy and paste. Whenever thinking is needed, it's marked with a "thinking" icon π€. Whenever customization is needed, it's marked with a "pencil" icon βοΈ. If the instructions are not clear, please let us know by opening a new Documentation issue describing where we can improve. Now on with the show...
- π€ - A "thinker" icon means that a little extra thinking may be required. Perhaps there are some choices to be made. Perhaps it's an optional step.
- βοΈ - A "pencil" icon means that the instructions may need modification before performing.
β οΈ - A "warning" icon means that something tricky is happening, so pay attention.
- https://github.com/senzing-garage/aws-cloudformation-ecs-poc-simple AWS Cloudformation
π€ The following tasks need to be complete before proceeding. These are "one-time tasks" which may already have been completed.
- Install Python dependencies:
- See requirements.txt for list
-
Get a local copy of template-python.py. Example:
-
βοΈ Specify where to download file. Example:
export SENZING_DOWNLOAD_FILE=~/self_signed_certificate.py
-
Download file. Example:
curl -X GET \ --output ${SENZING_DOWNLOAD_FILE} \ https://raw.githubusercontent.com/Senzing/aws-lambda-self-signed-certificate/main/self_signed_certificate.py
-
Make file executable. Example:
chmod +x ${SENZING_DOWNLOAD_FILE}
-
-
π€ Alternative: The entire git repository can be downloaded by following instructions at Clone repository
-
Run the command. Example:
${SENZING_DOWNLOAD_FILE}
π€ The following tasks need to be complete before proceeding. These are "one-time tasks" which may already have been completed.
- The following software programs need to be installed:
-
Run Docker container. Example:
docker run \ --interactive \ --rm \ --tty \ senzing/self-signed-certificate
Note: Because this is built to run in an AWS Lambda environment, errors will be seen when running outside of that environment.
The following instructions are used when modifying and building the Docker image.
π€ The following tasks need to be complete before proceeding. These are "one-time tasks" which may already have been completed.
For more information on environment variables, see Environment Variables.
-
Set these environment variable values:
export GIT_ACCOUNT=senzing export GIT_REPOSITORY=aws-lambda-self-signed-certificate export GIT_ACCOUNT_DIR=~/${GIT_ACCOUNT}.git export GIT_REPOSITORY_DIR="${GIT_ACCOUNT_DIR}/${GIT_REPOSITORY}"
-
Using the environment variables values just set, follow steps in clone-repository to install the Git repository.
Since the Docker image is based on public.ecr.aws/lambda/python:3.9
,
logging into AWS Elastic Container Registry (ECR) is required.
-
Set AWS environment variables. Example:
export AWS_ACCESS_KEY_ID=$(jq --raw-output ".Credentials.AccessKeyId" ~/aws-sts-get-session-token.json) export AWS_SECRET_ACCESS_KEY=$(jq --raw-output ".Credentials.SecretAccessKey" ~/aws-sts-get-session-token.json) export AWS_SESSION_TOKEN=$(jq --raw-output ".Credentials.SessionToken" ~/aws-sts-get-session-token.json) export AWS_DEFAULT_REGION=$(aws configure get default.region)
-
Login Example:
aws ecr-public get-login-password \ --region us-east-1 \ | docker login \ --username AWS \ --password-stdin public.ecr.aws/senzing
-
Option #1: Using
docker
command and GitHub.sudo docker build \ --tag senzing/template \ https://github.com/senzing-garage/template-docker.git#main
-
Option #2: Using
docker
command and local repository.cd ${GIT_REPOSITORY_DIR} sudo docker build --tag senzing/template .
-
Option #3: Using
make
command.cd ${GIT_REPOSITORY_DIR} sudo make docker-build
-
Download the AWS Lambda Runtime Interface Emulator and make executable. Example:
mkdir -p ~/aws-lambda-rie curl -Lo ~/aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie chmod +x ~/aws-lambda-rie/aws-lambda-rie
-
Run docker container to start a service. Example:
docker run \ --entrypoint /aws-lambda/aws-lambda-rie \ --interactive \ --publish 9001:8080 \ --rm \ --tty \ --volume ~/aws-lambda-rie:/aws-lambda \ senzing/self-signed-certificate \ /var/lang/bin/python -m awslambdaric self_signed_certificate.handler
-
In a separate terminal window, call the lambda. Example:
curl -v -X POST \ http://localhost:9001/2015-03-31/functions/function/invocations \ --data-binary @- << EOF { "RequestType": "Create", "ResponseURL": "", "StackId": "", "RequestId": "", "LogicalResourceId": "" } EOF
Make sure that the python3 --version
used to run the pip3 install
command is the same
as the python version seen in the AWS Lambda definition (i.e. the Runtime:
parameter).
If not the python packages may not be the correct version.
-
βοΈ Identify version of ZIP file. Example:
export SENZING_SELF_SIGNED_CERTIFICATE_VERSION=1.0.2
-
Prepare directories. Example:
sudo rm -rf ${GIT_REPOSITORY_DIR}/python mkdir -p ${GIT_REPOSITORY_DIR}/python/lib/python3.8/site-packages docker pull public.ecr.aws/sam/build-python3.8
-
Download dependencies. Example:
cd ${GIT_REPOSITORY_DIR} sudo docker run \ -v "$PWD":/var/task \ "public.ecr.aws/sam/build-python3.8" \ /bin/sh -c "pip install -r requirements.txt -t python/lib/python3.8/site-packages/; exit"
-
Compress dependencies. Example:
cd ${GIT_REPOSITORY_DIR}/python/lib/python3.8/site-packages zip -r ${GIT_REPOSITORY_DIR}/self-signed-certificate-${SENZING_SELF_SIGNED_CERTIFICATE_VERSION}.zip .
-
Add
self_signed_certificate.py
to compressed file. Example:cd ${GIT_REPOSITORY_DIR} zip -g self-signed-certificate-${SENZING_SELF_SIGNED_CERTIFICATE_VERSION}.zip self_signed_certificate.py
-
Upload
self-signed-certificate-0.0.0.zip
to AWS S3.
- See docs/errors.md.