title: How to add AssetCode to to a CfnFunction class
body: <p>I am wanting to be able to create a CfnFunction, but be able to pass in an AssetCode class for the <code>code</code> parameter. Normally, using the higher level <code>Function</code> construct provided by <code>aws_cdk.aws_lambda</code>, this would suffice:</p>
  <pre class="lang-py prettyprint-override"><code>class MyFunction(Stack):
      def __init__(self, scope, id, **kwargs):
          super().__init__(scope, id, **kwargs)
  
          self._python_function = Function(
              self,
              id=&quot;PythonFunction&quot;,
              runtime=Runtime.PYTHON_3_9,
              handler=&quot;app.main.lambda_handler&quot;,
              timeout=Duration.minutes(3),
              code=Code.from_asset(
                  path=&quot;/path/to/my/function&quot;,
                  bundling=BundlingOptions(
                      image=Runtime.PYTHON_3_9.bundling_image,
                      command=[
                          &quot;bash&quot;,
                          &quot;-c&quot;,
                          &quot;pip install -r requirements.txt -t /asset-output &amp;&amp; cp -au . /asset-output&quot;,
                      ],
                  ),
              ),
              memory_size=128,
              log_retention=RetentionDays.TWO_WEEKS,
          )
  </code></pre>
  <p>However, when trying to do that using the lower level CfnFunction construct, the documentation does not provide a clear example on how to pass in an AssetCode type:</p>
  <pre class="lang-py prettyprint-override"><code>class MyFunctionWrapper(Stack):
  
      def __init__(
              self,
              scope,
              id,
              **kwargs,
  
      ):
          super().__init__(scope, id, **kwargs)
  
          code_asset: AssetCode = Code.from_asset(
              path=&quot;path/to/my/code&quot;,
              bundling=BundlingOptions(
                  image=Runtime.PYTHON_3_9.bundling_image,
                  command=[
                      &quot;bash&quot;,
                      &quot;-c&quot;,
                      &quot;pip install -r requirements.txt -t /asset-output &amp;&amp; cp -au . /asset-output&quot;,
                  ],
              ),
          )
  
          self._role = Role(
              self,
              id=f&quot;{id}FunctionRole&quot;,
              managed_policies=[
                  ManagedPolicy.from_managed_policy_arn(
                      self,
                      id=&quot;PolicyArn&quot;,
                      managed_policy_arn=&quot;arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole&quot;,
                  )
              ],
              assumed_by=ServicePrincipal(&quot;lambda.amazonaws.com&quot;),
          )
  
          self._function = CfnFunction(
              self,
              id=&quot;Function&quot;,
              runtime=&quot;PYTHON_3_9&quot;,
              handler=&quot;app.handler&quot;,
              timeout=60,
              memory_size=128,
              role=self._role.role_name,
              code=code_asset,  # &lt;- This is incorrect type for CfnFunction
          )
  
          self._log_group = LogGroup(
              self,
              id=f&quot;{id}LogGroup&quot;,
              log_group_name=f&quot;/aws/lambda/{self._function.function_name}&quot;,
              retention=RetentionDays.FIVE_DAYS,
          )
  
  
  </code></pre>