- Package libraries
Don't skip or optimize these steps. Zip creation is funky.
python3 -m venv env
source env/bin/activate
pip3 install google-cloud-storage
deactivate
cd env/lib/python3.7/site-packages
zip -r9 ../../../../function.zip .
cd ../../../../
- Package code
zip function.zip list_buckets.py gcp.json
- Create S3 bucket
aws cloudformation create-stack \
--stack-name gcp-to-aws-storage \
--template-body file://cloudformation/s3.yml \
--region us-east-1
- Get S3 bucket name (may have to wait a few seconds)
aws cloudformation describe-stacks \
--stack-name gcp-to-aws-storage \
--query 'Stacks[0].Outputs[0].OutputValue' \
--output text
- Upload function code to S3
aws s3 cp function.zip s3://<bucket_name>
- Update the bucket name in
cloudformation/lambda-parameters.json
- Create the Lambda resources
aws cloudformation create-stack \
--stack-name gcp-to-aws-function \
--template-body file://cloudformation/lambda.yml \
--parameters file://cloudformation/lambda-parameters.json \
--capabilities CAPABILITY_NAMED_IAM \
--region us-east-1
- Log in to AWS Console
- Navigate to 'GCPtoAWS' function
- Create a test named 'test' with default payload
- Run the test
Expected output should look like this:
START RequestId: 07e75f2b-041f-4a25-b558-6f4e0162fc18 Version: $LATEST
[<Bucket: _____>, <Bucket: ____>, <Bucket: ____>]
END RequestId: 07e75f2b-041f-4a25-b558-6f4e0162fc18
REPORT RequestId: 07e75f2b-041f-4a25-b558-6f4e0162fc18 Duration: 1201.87 ms Billed Duration: 1300 ms Memory Size: 128 MB Max Memory Used: 81 MB
If you need to update your function code, use this short cut:
aws lambda update-function-code --function-name GCPtoAWS --zip-file fileb://function.zip
- Tear down storage
aws s3 rm --recursive s3://<bucket_name>
aws cloudformation delete-stack \
--stack-name gcp-to-aws-storage \
--region us-east-1
- Tear down function
aws cloudformation delete-stack \
--stack-name gcp-to-aws-function \
--region us-east-1
pip3 freeze > requirements.txt
pip3 install -f requirements.txt