bitter-horse-93353
05/02/2022, 6:02 PM# mypulumi/__main__.py
bucket = aws.s3.Bucket("bucket")
# myscript.py
from mypulumi import bucket
import boto3
bucket = boto3.client('s3').Bucket(bucket.id) # use the value from the pulumi stack script
Trying to understand if this is a support/common use case and what the best practices around this are. It feels like one benefit of having the definitions in python would be accessing them in various places and knowing that the IDs/ARNs/etc. will always match correctly.millions-furniture-75402
05/02/2022, 6:06 PMbitter-horse-93353
05/02/2022, 7:33 PMpulumi/buckets/pulumi.yaml
that defines the bucket & outputs the bucket ID using pulumi.export
and then in myscript.py
I would do
stack = auto.create_or_select_stack(stack_name="dev", work_dir="pulumi/buckets/")
up_res = stack.up(on_output=print)
up_res.outputs[xxx].value # bucket ID
and the assumption here is that if the buckets all exist already & are configured in the environment the same as they are in pulumi.yaml
then the call to stack.up
will essentially no-op & just return the relevant data?millions-furniture-75402
05/02/2022, 8:18 PMbitter-horse-93353
05/02/2022, 8:20 PM<s3://bucket>-{uuid}/
anywhere in my code, but instead always have pulumi.mybucket.id
which will always remain correct regardless of infra changesmillions-furniture-75402
05/02/2022, 8:21 PMbitter-horse-93353
05/02/2022, 8:22 PMmillions-furniture-75402
05/02/2022, 8:23 PMconst myBucket = new aws.s3.Bucket(`${appName}-bucket`, ...);
const lambdaFunctionApi = new aws.lambda.Function(
`${appName}-api`,
{
code: new pulumi.asset.FileArchive("./dist/app"),
memorySize: 128,
environment: {
variables: {
API_BASE_PATH: apiBasePath,
S3_BUCKET_NAME: myBucket.name.apply(v => v),
},
},
handler: "lambdaApiHandler.handler",
layers: [lambdaLayer.arn],
role: applicationRole.arn,
runtime: aws.lambda.NodeJS12dXRuntime,
timeout: 30,
vpcConfig: {
securityGroupIds: [appSecurityGroup.id, vpc.defaultSecurityGroupId],
subnetIds: privateSubnetIds,
},
},
{ dependsOn: [applicationRole, lambdaLayer] },
);