Hey everyone! I'm using pulumi as an in-line progr...
# getting-started
l
Hey everyone! I'm using pulumi as an in-line program and it's going great except I can't figure out how to save my state to S3 instead of locally. My eventual goal is to use a lambda to launch my pulumi stack, but I can't do this unless I can save and retrieve my state somewhere that isn't local. Thanks! 🙂
b
the automation api uses whatever your local pulumi CLI is using for state storage, so if you do
pulumi login <s3://bucket>
and rerun your program, it'll store your state there
l
@billowy-army-68599 That. Is. Amazing. Thanks for the quick response! I saw there's something with when you create a workspace you can set a backend url .. Is that necessary or can I just stick that as long as I run pulumi login with s3?
b
that also works too 🙂 either/or
l
Gotcha! Ideally, I want to use that then, but I can't seem to get it to work and, unfortunately, the docs don't have a great example. I'm writing in Python. Anyway you might be able to point me to what is wrong with the below?
Copy code
project_name = "shared_buildbot_stack"
stack_name = f'{project_name}-qa'

workspace = auto.LocalWorkspace(program=handler, env_vars={"PULUMI_CONFIG_PASSPHRASE": f'{stack_name}'},                           project_settings=auto.ProjectSettings(backend=auto.ProjectBackend(url=f'<s3://pulumi-state-randomid>'), name=project_name, runtime='python'))
I'd like to be able to invoke my pulumi program without touching the cli at all (ie, via lambda / using the serverless framework).
b
g
I think all you need is run select stack
Copy code
new_stack = auto.select_stack(
        stack_name=f"{owner}/{new_stack_name}", project_name=new_project_name, program=lambda: ""
    )
check the different parameters
l
@billowy-army-68599 I tried the above, but had to modify it some because it seems that wasn't exactly what is expected?
Copy code
project_settings = auto.ProjectSettings(
        name=project_name,
        runtime="python",
        backend=auto.ProjectBackend(url="<s3://pulumi-state>"))
    
    stack = auto.create_or_select_stack(stack_name=stack_name,
                                        project_name=project_name,
                                        program=handler,
                                        opts=auto.LocalWorkspaceOptions(project_settings=project_settings))
b
did that work?
l
I'm thinking this might be closer, but I'm getting this error now:
Copy code
stderr: error: could not create stack: An IO error occurred while writing the new snapshot file: blob (key ".pulumi/stacks/shared_buildbot_stack-qa.json") (code=Unknown): AuthorizationHeaderMalformed: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-central-1'
        status code: 400, request id: ZFGCTQPXZMC1EC1K, host id: ySdM1hFA7EPcNH+k+1iJqchDbQ36pQ0+rl/xuP/fC9X6ycxv0tMzvMPICQC6tbDoyVw4EV7I9Bc=
I haven't dug into it yet though. It could be that the bucket isn't unique globally or something.
That might have worked! It's at least deploying. Now I just need to see if the state gets saved to the bucket
It did! Thank you @billowy-army-68599 ! You were so helpful!!!
b
🎉 i actually asked @red-match-15116 for help, they're the real expert here
l
THank you @red-match-15116 then! 🙂
partypus 8bit 1
r
Happy to help 🙂
❤️ 1