MCPcopy Create free account
hub / github.com/aws-samples/aws-cdk-examples / on_create

Function on_create

python/iotcore/lambda/cert_handler.py:11–33  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

9secrets_manager = boto3.client('secretsmanager')
10
11def on_create(event):
12 response = iot.create_keys_and_certificate(setAsActive=True)
13 certificate_id = response['certificateId']
14 certificate_pem = response['certificatePem']
15 key_pair = response['keyPair']
16
17 if not certificate_id or not certificate_pem or not key_pair:
18 raise ValueError('Failed to create keys and certificate')
19
20 secrets_manager.create_secret(
21 Name=SECRET_NAME,
22 SecretString=json.dumps({
23 'cert': certificate_pem,
24 'keyPair': key_pair['PrivateKey']
25 })
26 )
27
28 return {
29 'PhysicalResourceId': certificate_id,
30 'Data': {
31 'certificateId': certificate_id
32 }
33 }
34
35def on_delete(event):
36 try:

Callers 1

lambda_handlerFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected