I faced a similar issue where I wanted a Lambda function to get data from an API that is behind a VPN, but I did not have any control over the client VPN. If you are able to install the required client-side VPN configuration with OpenSwan, then AWS Site-to-Site VPN is the correct answer. It will ensure that Lambda and other AWS services can interact cleanly with the services protected by the VPN.
If you cannot set up a site-to-site VPN, then it's not possible for Lambda to call the API directly. Your goal, then, may be to find some way to connect to the VPN as a client, call the API to get the data, and then store the data in the VPC.
Please note that this solution may not be appropriate for your use case. It works for me only because I need to periodically call the API to update data for analysis and reporting, which is currently done on my computer. I have access to the data through the API, but not directly to the databases or systems protected by the VPN.
- Set up a VPC with an internet gateway that is connected to the public internet. This includes the VPC, subnets, route tables, and the internet gateway. There are many guides online, but I used this "OpenVPN+VPC+VPN Client Configuration" video for guidance. The narrator sets up the VPC with public internet access beginning at 6:00.
- Launch an EC2 instance with an Amazon Linux 2 AMI.
- SSH into the new EC2 instance, and install the OpenVPN package (this StackOverflow thread contains instructions)
- Copy all necessary VPN configuration files to the EC2 instance along with your get scripts. I used SCP to complete this task. Because I use OpenVPN, I copied my .conf file over.
- Connect to the VPN through this EC2 instance and run your API scripts.
This allows you to get the data from the API into the EC2 instance, and from there the data could be stored in an S3 bucket, in DynamoDB, or in whatever form on the VPC that suits your needs best.
Note that the scripts and configuration files will be deleted by default when the instance is stopped or terminated. If you plan to use this method regularly to pull data, then it may be best to keep your files in an S3 bucket and transfer them to the EC2 as needed so that you don't have to SCP the files from your computer every time.
The VPC, subnets, route tables, and internet gateway do not need to be set up anew every time. They can remain in place and will incur no charge. You will incur charges with the EC2 instances.