I have an app stack that fires off a custom resource lambda on every deploy. Currently the custom resource lambda is in the same app stack and both are running in the same account. Both are built in Python 3.8
This is how its structured now where everything is in one stack running in the same account.
cust_res_lambda = _lambda.Function(
self, 'crLambda',
runtime=_lambda.Runtime.PYTHON_3_8,
code=_lambda.Code.from_asset('..'),
handler='lambda.lambda_handler',
function_name='customResourceLambda',
layers=[..,..],
)
cust_res_lambda.add_to_role_policy(_iam.PolicyStatement(
effect=_iam.Effect.ALLOW,
actions=[
'dynamodb:Query',
'dynamodb:GetItem',
'dynamodb:GetRecords',
'dynamodb:PutItem',
'dynamodb:UpdateItem',
'dynamodb:BatchGetItem',
],
resources=['arn:aws:dynamodb:XregionX:Xaccount-numX:table/stances']
))
res_provider = cr.Provider(
self,'crProvider',
on_event_handler= cust_res_lambda
)
now=datetime.now()
time = now.strftime("%H:%M:%S") # forces the execution of custom resource at every stack run.
CustomResource(self, 'cust_res',service_token= res_provider.service_token,properties={"prop1":"aa","prop2":"bb","res_id":time })
Looking for some documentation guidance around how to get the custom resource lambda deployed in a central account A, while the app stack gets deployed in accounts B,C,D? I will shift the lambda into its own stack that is only deployed in account A. The ask is due to the lambda needing to update a DynamoDB in the central account A and accounts B, C, D where the app stack will be deployed are not allowed to touch any resources in account A other than this custom resource lambda.
EDIT: There are some security restrictions why it may not be allowed to have the lambda run in accounts B, C, D in this particular case. Also, we don't know in advance all the other target accounts that this stack will be deployed in. The lambda needs to run from central account A.