What's the best way to do the following cloudforma...
# general
b
What's the best way to do the following cloudformation replacement:
!Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter${SsmParameterPrefix}*"
where ${AWS::*} are standard cloudformation values replaced at runtime by the current region/account id and ${SsmParameterPrefix} is a passed in value as a parameter.
One solution:
Copy code
type AwsData = {
    region: string,
    accountId: string,
}
type FnSubCallback = (data: AwsData) => string
function fnSub(fn: FnSubCallback, provider?: aws.Provider) {
    const
        opts = {provider: provider},
        callerId = aws.getCallerIdentity(opts),
        region = aws.getRegion({}, opts)

    return pulumi
        .all([callerId, region])
        .apply(
            ([callerId, region]) => {
                const data: AwsData = {
                    region: region.name,
                    accountId: callerId.accountId,
                }
                return fn(data)
            }
        )
}
Used like:
Copy code
const myarn = fnSub(AWS => `arn:aws:ssm:${AWS.region}:${AWS.accountId}:parameter${SsmParameterPrefix}*`
my bad this doesn't work
aws.getRegion/getCallerIdentity seem to need providers using keys
This fixes the above:
AWS_SDK_LOAD_CONFIG=true pulumi up