https://pulumi.com logo
Title
r

rich-action-28775

04/06/2021, 2:11 PM
Hello everyone! I was wondering, is there any way to initialize and use a Pulumi client from within my code? Meaning that instead of running
pulumi up
using the CLI, I'll have something like the following (python): main.py
from pulumi import client
from pulumi_aws import s3

# Initialize the Pulumi client
pulumi_client = PulumiClient()

# Provision a S3 bucket
web_bucket = s3.Bucket('s3-example-bucket')

pulumi_client.up()
pulumi_client.destroy()
Now instead of running
pulumi up
followed by a
pulumi destroy
, running this piece of code can be done by running:
python main.py
This is a very raw example, so please tell me if there's anything else you'd like me to elaborate on. Thanks in advance! :)
🙌 1
b

brave-planet-10645

04/06/2021, 2:15 PM
You should check out our automation api - that'll do pretty much all you've described there
r

rich-action-28775

04/06/2021, 3:13 PM
thanks, looks awesome! taking a look 🙏
b

broad-dog-22463

04/06/2021, 3:18 PM
there are some great Python examples here @rich-action-28775 - https://github.com/pulumi/automation-api-examples/tree/main/python
🙌 1
b

billowy-army-68599

04/06/2021, 3:32 PM
@rich-action-28775 i just put the finishing touches on this guided tour as well, so take a look here: https://github.com/jaxxstorm/pulumi-automationapi-workshop Feedback appreciated!
🙏 1