https://pulumi.com logo
Title
l

lemon-dog-29241

08/05/2021, 8:08 PM
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

billowy-army-68599

08/05/2021, 8:10 PM
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

lemon-dog-29241

08/05/2021, 8:15 PM
@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

billowy-army-68599

08/05/2021, 8:15 PM
that also works too πŸ™‚ either/or
l

lemon-dog-29241

08/05/2021, 8:17 PM
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?
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

billowy-army-68599

08/05/2021, 8:45 PM
g

great-sunset-355

08/05/2021, 8:46 PM
I think all you need is run select stack
new_stack = auto.select_stack(
        stack_name=f"{owner}/{new_stack_name}", project_name=new_project_name, program=lambda: ""
    )
check the different parameters
l

lemon-dog-29241

08/05/2021, 9:06 PM
@billowy-army-68599 I tried the above, but had to modify it some because it seems that wasn't exactly what is expected?
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

billowy-army-68599

08/05/2021, 9:06 PM
did that work?
l

lemon-dog-29241

08/05/2021, 9:07 PM
I'm thinking this might be closer, but I'm getting this error now:
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

billowy-army-68599

08/05/2021, 9:11 PM
πŸŽ‰ i actually asked @red-match-15116 for help, they're the real expert here
l

lemon-dog-29241

08/05/2021, 9:11 PM
THank you @red-match-15116 then! πŸ™‚
πŸ˜›artypus-8bit: 1
r

red-match-15116

08/05/2021, 10:46 PM
Happy to help πŸ™‚
❀️ 1